Package ezknitr. September 16, 2016

Similar documents
Package SASmarkdown. R topics documented: November 30, Version Date Title 'SAS' Markdown

Package spelling. December 18, 2017

Package revealjs. R topics documented: March 13, Type Package

Package workflowr. July 6, 2018

Package radix. September 17, 2018

Package knitrbootstrap

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package docxtools. July 6, 2018

Package semver. January 6, 2017

Package ECctmc. May 1, 2018

Package internetarchive

Package calpassapi. August 25, 2018

Package ggextra. April 4, 2018

Package pdfsearch. July 10, 2018

Package WordR. September 7, 2017

Package messaging. May 27, 2018

Package knitrprogressbar

Package slickr. March 6, 2018

Package fastdummies. January 8, 2018

Package liftr. R topics documented: May 14, Type Package

Package validara. October 19, 2017

Package R.rsp. January 11, 2018

Package robotstxt. November 12, 2017

Package SNPediaR. April 9, 2019

Package datasets.load

Package htmlwidgets. February 25, 2016

Package canvasxpress

Package tabulizer. June 7, 2018

Package rprojroot. January 3, Title Finding Files in Project Subdirectories Version 1.3-2

Package githubinstall

Package loggit. April 9, 2018

Package htmlwidgets. July 10, 2017

Package jstree. October 24, 2017

Package zip. R topics documented: March 11, Title Cross-Platform 'zip' Compression Version 2.0.1

Package GetoptLong. June 10, 2018

Package clipr. June 23, 2018

Package ezsummary. August 29, 2016

Package texpreview. August 15, 2018

Package modules. July 22, 2017

Package triebeard. August 29, 2016

Package cronr. March 3, 2017

Package virustotal. May 1, 2017

Package kdtools. April 26, 2018

Package goodpractice

Package essurvey. August 23, 2018

Package BiocStyle. April 22, 2016

Package datapasta. January 24, 2018

Package ssh. June 4, 2018

Package barcoder. October 26, 2018

Package SEMrushR. November 3, 2018

Package fastqcr. April 11, 2017

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package shinyhelper. June 21, 2018

R topics documented: 2 checkpoint-package

Package condusco. November 8, 2017

Package httpcache. October 17, 2017

Package shiny.semantic

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package msgtools. March 2, 2017

Package data.world. April 5, 2018

Package gifti. February 1, 2018

Package statsdk. September 30, 2017

Package climber. R topics documented:

Package vdiffr. April 27, 2018

Package rcmdcheck. R topics documented: November 10, 2018

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package lumberjack. R topics documented: July 20, 2018

Package opencage. January 16, 2018

Package BiocStyle. January 26, 2018

Package dbx. July 5, 2018

Package shinyfeedback

Package RODBCext. July 31, 2017

Package cloudml. June 12, 2018

Package fitbitscraper

Package postgistools

Package patentsview. July 12, 2017

Package weco. May 4, 2018

Package mixsqp. November 14, 2018

Package GetITRData. October 22, 2017

Package keyholder. May 19, 2018

Package profvis. R topics documented:

Package nngeo. September 29, 2018

Package widyr. August 14, 2017

Package bigqueryr. October 23, 2017

Package qualmap. R topics documented: September 12, Type Package

Package benchmarkme. R topics documented: February 26, Type Package Title Crowd Sourced System Benchmarks Version 0.2.

Package repec. August 31, 2018

Package rwars. January 14, 2017

Package BiocStyle. December 9, 2018

Package gtrendsr. October 19, 2017

Package resumer. R topics documented: August 29, 2016

Package available. November 17, 2017

Package bigqueryr. June 8, 2018

Package tiler. June 9, 2018

Package algorithmia. September 13, 2016

Package wikitaxa. December 21, 2017

Package oec. R topics documented: May 11, Type Package

Package tibble. August 22, 2017

Package mdftracks. February 6, 2017

Package wrswor. R topics documented: February 2, Type Package

Transcription:

Package ezknitr September 16, 2016 Title Avoid the Typical Working Directory Pain When Using 'knitr' Version 0.6 An extension of 'knitr' that adds flexibility in several ways. One common source of frustration with 'knitr' is that it assumes the directory where the source file lives should be the working directory, which is often not true. 'ezknitr' addresses this problem by giving you complete control over where all the inputs and outputs are, and adds several other convenient features to make rendering markdown/html documents easier. URL https://github.com/ropenscilabs/ezknitr BugReports https://github.com/ropenscilabs/ezknitr/issues Depends R (>= 3.0.2) Imports knitr (>= 1.7), markdown (>= 0.7), R.utils (>= 1.34.0) Suggests testthat (>= 0.9.1), rmarkdown License MIT + file LICENSE SystemRequirements pandoc with https support LazyData true VignetteBuilder knitr RoxygenNote 5.0.1 NeedsCompilation no Author Dean Attali [aut, cre] Maintainer Dean Attali <daattali@gmail.com> Repository CRAN Date/Publication 2016-09-16 07:13:44 R topics documented: ezknitr............................................ 2 ezknitr_core......................................... 2 open_output_dir....................................... 4 setup_ezspin_test...................................... 5 set_default_params..................................... 6 1

2 ezknitr_core Index 7 ezknitr ezknitr Details Avoid the Typical Working Directory Pain When Using knitr ezknitr is an extension of knitr that adds flexibility in several ways. One common source of frustration with knitr is that it assumes the directory where the source file lives should be the working directory, which is often not true. ezknitr addresses this problem by giving you complete control over where all the inputs and outputs are, and adds several other convenient features to make rendering markdown/html documents easier. ezknitr_core Knit Rmd or spin R files without the typical pain of working directories ezknitr is an extension of knitr that adds flexibility in several ways. One common source of frustration with knitr is that it assumes the directory where the source file lives should be the working directory, which is often not true. ezknitr addresses this problem by giving you complete control over where all the inputs and outputs are, and adds several other convenient features. The two main functions are ezknit and ezspin, which are wrappers around knitr s knit and spin, used to make rendering markdown/html documents easier. ezspin(file, wd, out_dir, fig_dir, out_suffix, params = list(), verbose = FALSE, chunk_opts = list(tidy = FALSE), keep_rmd = FALSE, keep_md = TRUE, keep_html = TRUE, move_intermediate_file = TRUE,...) ezknit(file, wd, out_dir, fig_dir, out_suffix, params = list(), verbose = FALSE, chunk_opts = list(tidy = FALSE), keep_md = TRUE, keep_html = TRUE) Arguments file wd The path to the input file (.Rmd file if using ezknit or.r script if using ezspin). If wd is provided, then this path is relative to wd. The working directory to be used in the Rmd/R script. Defaults to the current working directory (note that this is not the same behaviour as knitr). See the Detailed Arguments section for more details.

ezknitr_core 3 Details Value out_dir fig_dir out_suffix params verbose The output directory for the rendered markdown or HTML files (if wd is provided, then this path is relative to wd). Defaults to the directory containing the input file. The name (or path) of the directory where figures should be generated. See the Detailed Arguments section for more details. A suffix to add to the output files. Can be used to differentiate outputs from runs with different parameters. The name of the output files is the name of the input file appended by out_suffix, separated by a dash. A named list of parameters to be passed to use in the input Rmd/R file. For example, if the script to execute assumes that there is a variable named DATASET_NAME, then you can use params = list('dataset_name' = 'oct10dat'). If TRUE, then show the progress of knitting the document. chunk_opts List of knitr chunk options to use. See?knitr::opts_chunk for a list of available chunk options. keep_rmd, keep_md Should intermediate Rmd or md files be kept (TRUE) or deleted (FALSE)? keep_html Should the final html file be kept (TRUE) or deleted (FALSE)? move_intermediate_file Should the intermediate Rmd file be moved to the output folder (TRUE) or stay in the same folder as the source R file (FALSE)?... Any extra parameters that should be passed to knitr::spin. If you have a very simple project with a flat directory structure, then knitr works great. But even something as simple as trying to knit a document that reads a file from a different directory or placing the output rendered files in a different folder cannot be easily done with knitr. ezknitr improves basic knitr functionality in a few ways. You get to decide: What the working directory of the source file is Where the output files will go Where the figures used in the markdown will go Any parameters to pass to the source file The path to the output directory (invisibly). Detailed Arguments All paths given in the arguments can be either absolute or relative. The wd argument is very important and is set to the current working directory by default. The path of the input file and the path of the output directory are both relative to wd (unless they are absolute paths). Moreover, any code in the R script that reads or writes files will use wd as the working directory.

4 open_output_dir The fig_dir argument is relative to the output directory, since the figures accompanying a markdown file should be placed in the same directory. It is recommended to either leave fig_dir as default or set it to a different name but not to a different directory. Because of the way knitr works, there are a few known minor issues if fig_dir is set to a different directory. Difference between ezknit and ezspin ezknit is a wrapper around knitr::knit while ezspin is a wrapper around ezspin. The two functions are very similar. knit is the more popular and well-known function. It is used to render a markdown/html document from an Rmarkdown source. spin takes an R script as its input, produces an Rmarkdown document from the R script, and then calls knit on it. See Also open_output_dir setup_ezknit_test setup_ezspin_test set_default_params knit spin ## Not run: tmp <- setup_ezknit_test() ezknit("r/ezknit_test.rmd", wd = "ezknitr_test") ezknit("r/ezknit_test.rmd", wd = "ezknitr_test", out_dir = "output", fig_dir = "coolplots", params = list(numpoints = 50)) unlink(tmp, recursive = TRUE, force = TRUE) tmp <- ezspin("r/ezspin_test.r", wd = "ezknitr_test") ezspin("r/ezspin_test.r", wd = "ezknitr_test", out_dir = "output", fig_dir = "coolplots", params = list(numpoints = 50), keep_rmd = TRUE) unlink(tmp, recursive = TRUE, force = TRUE) ## End(Not run) open_output_dir Open the directory containing the output from the last ezknitr command Call this function after running ezspin or ezknit to open the resulting output directory in your file browser. This is simply a convenience function so that if you want to see the results you don t need to navigate to the appropriate folder manually.

setup_ezspin_test 5 ## Not run: library(ezknitr) ezspin("r/ezspin_test.r", wd = "ezknitr_test") ## End(Not run) setup_ezspin_test Set up a test directory to experiment with ezspin or ezknit Value Create a few directories that try to mimic a real data-analysis project structure, and add a data file and a simple R script (for ezspin) or Rmarkdown file (for ezknit). After setting up these files and directories, you can run ezknitr commands and their equivalent knitr commands to compare and see the benefits of using ezknitr. See Also More specific instructions on how to interact with this test directory will be printed to the console. setup_ezknit_test() The path to the test directory. ezspin spin ezknit knit open_output_dir ## Not run: library(ezknitr) # setup the test directory structures and run naive spin knitr::spin("ezknitr_test/r/ezspin_test.r") file.remove(c("ezspin_test.md", "ezspin_test.html")) # setup the test directory structures and run simple ezspin

6 set_default_params ezspin("r/ezspin_test.r", wd = "ezknitr_test") # setup the test directory structures and run ezspin with more parameters tmp <- ezspin("r/ezspin_test.r", wd = "ezknitr_test", out_dir = "output", fig_dir = "coolplots") unlink(tmp, recursive = TRUE, force = TRUE) ## End(Not run) set_default_params Set default parameters Create variables with the given values only if these variables do not currently exist. set_default_params(params) Arguments params List of parameters. Details Sometimes it may be useful to define a variable only it hasn t been defined yet. One example where this can be useful is when you have an Rmd script that uses some variables and you want to be able to use custom values for these variables, but also give them a default value in the script in case they are not set beforehand. exists("foo") exists("bar") foo <- 5 set_default_params(list(foo = 10, bar = 20)) print(foo) print(bar)

Index ezknit, 4, 5 ezknit (ezknitr_core), 2 ezknitr, 2 ezknitr-package (ezknitr), 2 ezknitr_core, 2 ezspin, 4, 5 ezspin (ezknitr_core), 2 knit, 4, 5 open_output_dir, 4, 4, 5 set_default_params, 4, 6 setup_ezknit_test, 4 setup_ezknit_test (setup_ezspin_test), 5 setup_ezspin_test, 4, 5 setup_test (setup_ezspin_test), 5 spin, 4, 5 7