官术网_书友最值得收藏!

The R Markdown interface

After our first steps with R Markdown and our sample report, it is time to take a closer look at the R Markdown interface within the RStudio IDE.

Inspecting the R Markdowns panes

In the following screenshot, you can easily see that three panes play a role in the creation process of R Markdown documents:

We already know the Files pane, where the code and text of the report can be created. As recommended, the output of the .Rmd file is shown in the Viewer pane. Next to the console pane is the R Markdown console, where you inspect the processing and creation of the .Rmd file. If there are any code errors in your R Markdown file, the execution will be stopped and two new buttons will appear in the right corner.

While the Output window shows the normal processing until reaching the first error, the Issues window shows only the respective errors and the associated line, where the error seems to be.

Explaining the R Markdown File pane settings

In the File pane, various settings can be made. The following sections explain the details in the screenshot.

File tab arrows

At the top left corner, you will see two arrows. While a click on the right-facing arrow lets you go back to the previous source location, the left-facing arrow lets you go forward to the next source location.

Saving current document

On the right-hand side, there is a button to save the R Markdown document. When you make changes to your .Rmd file in the File pane, hitting the Save button will not affect the output. To apply all the changes, you need to knit the file again. Then your output file will finally reflect the changes in your .Rmd file.

Spell check

Next you can check the spelling of your text with a click on the Spell check icon. If there are no spelling errors, a small popup will appear; it will show that the spell check is complete. If there are any errors, another popup window will turn up and show you every word that seems to be wrong. When you are writing really long reports, the spelling check is a very handy tool.

Find/replace

Next, we see a magnifier icon called find/replace. This great tool was already described in Chapter 1, The RStudio IDE – an Overview and it helps you find and replace text and code on the fly.

Question mark

A click on the question mark icon, ?, will give you two more references to select:

  • Using R Markdown: This will open a new page in your browser heading to the R Markdown reference page of RStudio (http://rmarkdown.rstudio.com/)
  • Markdown Quick Reference: A click on this will open a new view in the help pane of RStudio, presenting a brief overview of the most important Markdown formatting options.

Knit HTML

As we already know, this button starts the knitting process of our R Markdown file and outputs an HTML file. A click on the down-facing arrowhead gives you the option to choose from among HTML, PDF, or Word as the output format.

Gear icon

The gear icon not only lets you edit the output format again, but also dives a lot deeper with several settings related to the chosen format.

Output Format: HTML

HTML is the standard and recommended output format. There are three areas in which settings can be made as you can see in the following screenshot:

Following is a description of the various tabs displayed in the preceding screenshot:

  • In the General tab, you can adjust settings such as which syntax highlighting you prefer, whether you want to apply a custom CSS file to your reports, and more.
  • The Figures tab lets you set a default height and width in inches for all the generated plots. Further, you can check whether you want to render your figures with captions.
  • The Advanced tab gives you three more sophisticated options to check. For example, using smart punctuation will automatically produce a typographically correct output.

Output Format – PDF

PDF as an output format also offers three setting areas:

Following is a description of the various tabs displayed in the preceding screenshot:

  • In the General tab, you can adjust the settings to include a table of contents, select a syntax highlighting, and more
  • The Figures tab for the PDF output shows the same settings as the HTML output settings, but you can also check whether the figures should be cropped
  • In the Advanced tab, you can select a LaTeX engine and choose whether you want to keep the Tex source file

Output Format – Word

If you like, you can also choose the output of a knitted document to be a Word file. The Word options window offers two setting areas. They are shown in the following screenshot:

Following is a description of the various tabs displayed in the preceding screenshot:

  • The General tab only gives you the option to select a syntax highlighting
  • The Figures tab offers the same settings as the HTML settings

Run and re-run icons

The run and re-run icons, already known from normal .R files, allows you to run the code of a selected line, run the corresponding selection, or re-run the previous code region.

Chunks

The Chunks button opens a drop-down menu from where you can choose several options:

You can insert a plain R code chunk or jump between the existing chunks in your file. Moreover, you can run the previous, current, and next chunk, or you can run them all at once. The output of the chunks will be displayed in the normal console pane.

Jump to menu

The jump to menu also works for faster navigation through your code chunks. When you label each code chunk, it gets even easier to jump to the right chunk.

Viewer pane options

The following option is also available when you open your R Markdown output in an extra window:

A click on the Publish button will make it possible to directly publish your R Markdown file on http://rpubs.com/.

主站蜘蛛池模板: 利川市| 和平县| 丰宁| 永济市| 大埔县| 尚义县| 揭西县| 玛沁县| 宿松县| 边坝县| 东阿县| 伽师县| 芮城县| 赤峰市| 临武县| 密山市| 青岛市| 比如县| 明光市| 东源县| 金川县| 绥棱县| 孟津县| 会昌县| 广安市| 绥江县| 塘沽区| 桃园市| 东乡族自治县| 黄浦区| 北票市| 西乌| 海原县| 嘉黎县| 永川市| 沾化县| 宁河县| 商都县| 苗栗县| 佛冈县| 哈尔滨市|