LazyScript: Interact between scripts, and rmarkdown files

Description Usage Arguments Details Value Functions Author(s) See Also Examples

Description

The LazyScript serie provides functions that can copy/run code between script and rmd files. LazyScript is a R6 class, but the functions here provides means for user to use LazyScript instead of handling the R6 system. See functions below for detailed usage. See http://pkg.yangzhuoranyang.com/lazytype/ for more documentations.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
read_script(script_path, library = TRUE)

LazyScript %run% chunk_name

copy_script_to_rmd(
  script_path,
  rmd_path = NULL,
  saveAll = TRUE,
  match_chunk = TRUE,
  update = FALSE
)

remove_rmd_chunk(rmd_path, match_labels = NULL)

update_script_to_rmd(script_path, rmd_path = NULL, saveAll = TRUE)

Arguments

script_path

String. The path to the script.

library

Logical. Whether the library chunk (if there is one in the script) is ran when read in the script

LazyScript

A LazyScript object.

chunk_name

String. The label of the chunk in the script that you want to run.

rmd_path

String. The path to the rmarkdown file. The default is the file currently opened in the Rstudio editor.

saveAll

Logical. Whether save all open file in the editor. If FALSE, unsaved changes may be lost.

match_chunk

Logical. If TRUE, the function tries to find chunks in the script matching the chunks in the rmd file and make the copy to the corresponding chunks If FALSE, the chunks are appended to the end of the rmd file.

update

Logical. If both match_chunk and update are TRUE, remove the existing contents in the chunk before copy-and-paste

match_labels

Vector of characters. The name of the chunk where contents to be removed. If NULL, remove contents for all chunks except setup.

Details

The LazyScript serie generally depends on the prul header ## ---- to seperate the sections in the script. See insert_purl_section for addin to insert this header quickly. It is also the head that knitr::read_chunk uses to regonise chunks.

Value

A LazyScript object

Functions

Author(s)

Yangzhuoran Yang

See Also

knitr::read_chunk, insert_purl_section, insert_run_operator

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
test_script <- read_script("test.R")

test_script %run% "hello"

copy_script_to_rmd("test.R", "test.Rmd")


## End(Not run)

FinYang/lazytype documentation built on Sept. 3, 2020, 9:32 p.m.