Open In App

Run R Markdown in kaggle

Last Updated : 05 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Kaggle allows you to compile your RMarkdown files, as developed in RStudio for example, into a report on Kaggle. This very instruction was made in RMarkdown. Below the steps to do this with your RMarkdown file are detailed.

Create a New Notebook

Create a New Notebook

Create a New Notebook

You can make a new notebook from the Notebooks section or a competition page. The latter is preferable if you want to make sure you have all the input data files in the …/input directory available. Otherwise, you may need to separately upload all the data files, or add them from the fair competition.

Set the Language to R

Select the R Language as the backend Kernel

Select the R Language as the backend Kernel

Change the Editor Type in the File Menu

Using the Notebook option in the Editor

Using the Notebook option in the Editor

Once the Notebook has fully started, the first thing to do is change the Editor Type in the,

File Menu > Editor Type to Script.

Change the Language in Settings

Selecting R MarKdown Notebook

Selecting R Markdown Notebook

By changing the Editor Type to Script, the interface changes to source code only. In the setting, you now can select ‘RMarkdown’ under the Language option (Note: this option is not available when Editor Type is Notebook.)

Copy the RMarkdown code

 

When copying the RMarkdown code, make sure you include the YAML header and everything you want to include in your report. For nicer code formatting and a Table of Content change the header to this example.

Paste the code into Kaggle

Writing code in the R Markdown Notebook

Writing code in the R Markdown Notebook

Replace all the existing code in the Kaggle Script Editor. Make sure you check that Language in Settings shows ‘RMarkdown’.

Save & Run All (Commit)

Saving a R Markdown Notebook

Saving a R Markdown Notebook

Click the [⟳ Save Version] button. Make sure you select “Save & Run All (Commit)” in the popup screen. Then click Save. A small popup status window now shows that your file is being compiled by knitr.

Open the Viewer

Using viewer to see the output of the codes

Using a viewer to see the output of the codes

Once your file has been compiled the popup status window should look like this. Click the View link to go to the viewer to see the output. You can also click on the number in the right portion of the [Save Version] button. If you get an error message, make sure your RMarkdown runs without errors in your RStudio environment. If that’s the case, make sure that you have all the files that your script relies on the present in the “../input” directory, and that all pathnames in your script refer to the correct location.

For instance, make sure you use,

--> mydat <- read_csv("../input/mydata.csv")

and not for example

--> mydat <- read_csv("C:\\Users\\Desktop\\Datamydata.csv")

Verify the output and share the URL

Sharing the R Markdown Notebook

Sharing the R Markdown Notebook

You will have to change the sharing modus to Public by clicking the [Sharing] button and changing the setting. Then copy the URL to share your RMarkdown report.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads