insertQuietChunk: Insert a 'quiet' code chunk into an R Markdown file

Description Usage Arguments Value Examples

Description

This function can be used to insert any line or lines of code into an R Markdown file 'quietly'. The chunk will be inserted into the file called filename.Rmd, which must exist in the current working directory. Chaining with %>% is possible, by returning filename from the function. insertQuietChunk will insert a code chunk that will only show the results of the code in the rendered document.

Usage

1
insertQuietChunk(filename, object, chunktitle = NULL)

Arguments

filename

Character giving the name of the R Markdown file that the chunk should be inserted into, minus the .Rmd extension

object

Can be any quoted or unquoted line of R code, i.e. a call to a function to insert a single line. To insert more than one line, pass as a vector of type "expression".

chunktitle

Single or vector of character/s giving an optional markdown header that will be included before the code chunk e.g. of the form "# Header", "## Header", "### Header". Pass as a vector of titles of equal length to object expressions if multiple headers required.

Value

Returns filename so that functions can be chained to write to the same file consecutively

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 

## Insert single chunk, chained from createFile() function

createFile("Mtcars") %>% insertYAML(title = "Test", author = "J. Bloggs") %>%
                         insertLibraries() %>%
                         insertQuietChunk(summary(mtcars), title = "#Summary")

                         insertChunk("summary(mtcars)", title = "#Summary") would also work

## Insert multiple chunks to existing file, with headers

insertQuietChunk("Mtcars.Rmd",
                 expression(
                      plot(mtcars$cyl, mtcars$hp),
                      multivariateCorrelation(mtcars)),
                            title= c("##Scatter Plot",
                                     "##Correlations"))

## End(Not run)

elastacloud/automatic-data-explorer documentation built on May 8, 2019, 9:29 a.m.