R Markdown Tips
Posted on Jun 09, 2016 in Programming
Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.
** Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives. **
-
The
rmarkdown
package is preferred to themarkdown
package. There is also a small bug with themarkdown
package.markdown::markdownToHTML
does not render markdown title of the format##Title
correct. A space is required after#
formarkdownToHTML
to work. However,rmarkdown::render
works well on both situations. -
There are several ways to pass values between the R workspace and R Markdown. One way is to use global variables (from the R workspace) in R Markdown directly. However, you have to tell R Markdown the right working environment using the option
envir = 0
. Without this, R Markdown uses the current working environment which might not be the global working environment (e.g., whenknit
is called inside a function). Sometimes, it is more convenient to substitute patterns in R Markdown with required values directly. Make sure to use unique patterns if you do it in this. For example, if you want to pass a variablesite
by substituting into R Markdown, a good way is to replace pattern${site}
(instead of plainsite
) with the value of the variablesite
. -
Avoid doing complicated calculations in RMakrdown. Separted the code for calculation, etc., and use rmakrdown for reporting purpose mostly ...,
-
plotly
(for graphics) andDT
(for tables) are great visualization tools to use with R Markdown.