
Let’s learn a new way to apply if-else logic - the function ifelse. # site_no dateTime Flow Flow_cd Wtemp pH DO Wtemp_F # use "!any" if you don't want any of the values to meet some condition (e.g. If you did not complete the Clean lesson (or are starting in a new R session), just load in the cleaned csv by downloading it from here, saving it in a folder called “data”, and using read.csv (see below). If you successfully completed the Clean lesson, then you should have the cleaned up version of the data frame. Remember that we are using the NWIS dataset for all of these lessons. This will be a very high level introduction to both concepts, but should hopefully give you a jumping off place for more learning.
ADDING A CHUNK OF RCODE HOW TO
To do this effectively we need to understand how to create reusable R code and create reproducible reports. All that is left is to be able to write it up in such a way that others can not only understand what we did, but repeat it exactly on their own machines. You can use percentages, e.g., out.You now have a basic understanding of how to conduct a typical data analysis workflow in R. Out.width and out.height: The output size of R plots in the output document. You can also specify the two options together in a single chunk option fig.dim, e.g., fig.dim = c(6, 4) means fig.width = 6 and fig.height = 4. R plots in code chunks are first recorded via a graphical device in knitr, and then written out to files.
/yaootaweb-production/media/crawledproductimages/4c361c8da0d68058b1fa3478e050d50b37b3a405.jpg)
Caching can be handy but also tricky sometimes.įig.width and fig.height: The (graphical device) size of R plots in inches. However, I want to honestly remind you of the two hard problems in computer science (via Phil Karlton): naming things, and cache invalidation.

If caching is enabled, the same code chunk will not be evaluated the next time the document is compiled (if the code chunk was not modified), which can save you time. When you are trying to set echo = FALSE, results = 'hide', warning = FALSE, and message = FALSE, chances are you simply mean a single option include = FALSE instead of suppressing different types of text output individually.Ĭache: Whether to enable caching. When include = FALSE, this whole code chunk is excluded in the output, but note that it will still be evaluated if eval = TRUE. Include: Whether to include anything from a code chunk in the output document. Similarly, when warning = FALSE or message = FALSE, these messages will be shown in the R console. Note that if you set error = FALSE, rmarkdown::render() will halt on error in a code chunk, and the error will be displayed in the R console. Warning, message, and error: Whether to show warnings, messages, and errors in the output document. The default collapse = FALSE means R expressions and their text output are separated into different blocks. This is mostly cosmetic: collapse = TRUE makes the output more compact, since the R source code and its text output are displayed in a single output block. By default, text output will be wrapped in verbatim elements (typically plain code blocks).Ĭollapse: Whether to merge text output and source code into a single code block in the output. Results: When set to 'hide', text output will be hidden when set to 'asis', text output is written “as-is,” e.g., you can write out raw Markdown text from R code (like cat('**Markdown** is cool.\n')). We list a subset of them below:Įcho: Whether to echo the source code in the output document (someone may not prefer reading your smart source code but only results). There are a large number of chunk options in knitr documented at. 19.7 Output arguments for render functions.16.5.4 Create a widget without an R package.2.1.4 2017 Employer Health Benefits Survey.
