R Under development (unstable) (2025-12-17 r89193 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Use a temporary directory ---------------------------- > owd = getwd() > td = tempdir() > setwd(td) > > # Test -------------- > library(knitrdata) > library(magrittr) # For pipe operator > > # Create new Rmarkdown document > if (file.exists("test.create_chunks.Rmd")) + file.remove("test.create_chunks.Rmd") > rmarkdown::draft("test.create_chunks.Rmd","github_document","rmarkdown", + edit=FALSE) > > # List all chunks in document > chunklst = list_rmd_chunks(file="test.create_chunks.Rmd") > chunklst type label start end 1 r setup 6 8 2 r cars 18 20 3 r pressure 26 28 > > # Remove the pressure chunk > xx = split_rmd_by_chunk(file="test.create_chunks.Rmd",chunk_label="pressure") > txt = c(xx$pre_chunk,xx$post_chunk) > writeLines(txt,"test.create_chunks.Rmd") > > # List chunks again > chunklst = list_rmd_chunks(file="test.create_chunks.Rmd") > chunklst type label start end 1 r setup 6 8 2 r cars 18 20 > > # Remove all but setup chunk > remove_chunks(file="test.create_chunks.Rmd", + chunk_labels = 2:nrow(chunklst), + output.file="test.create_chunks.Rmd") > > # List all chunks again > chunklst = list_rmd_chunks(file="test.create_chunks.Rmd") > chunklst type label start end 1 r setup 6 8 > > # Create some binary data > x = data.frame(a=1:10,b=(1:10)^2) > saveRDS(x,"test.create_chunks.RDS") > > # Push chunks into Rmarkdown document > # Insert in reverse order to not have to figure out line number > txt = create_chunk(chunk_label="plot",c("x","plot(b~a,data=x)"),chunk_type="r") %>% + insert_chunk(11,rmd.file="test.create_chunks.Rmd") > txt = data_encode("test.create_chunks.RDS","base64") %>% + create_chunk(chunk_label="thedata",output.var="x",format="binary",loader.function=readRDS) %>% + insert_chunk(11,txt) > txt = create_chunk(chunk_label="loadknitrdata","library(knitrdata)",chunk_type="r") %>% + insert_chunk(11,txt) > > writeLines(txt,"test.create_chunks.Rmd") > > # List all chunks again > chunklst = list_rmd_chunks(file="test.create_chunks.Rmd") > chunklst type label start end 1 r setup 6 8 2 r loadknitrdata 11 13 3 data thedata 14 20 4 r plot 21 24 > > # Render document to test > if (rmarkdown::pandoc_available(version="1.12.3")) + rmarkdown::render("test.create_chunks.Rmd") processing file: test.create_chunks.Rmd output file: test.create_chunks.knit.md "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS test.create_chunks.knit.md --to gfm+tex_math_dollars-yaml_metadata_block --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.create_chunks.md --template "D:\RCompile\CRANpkg\lib\4.6\rmarkdown\rmarkdown\templates\github_document\resources\default.md" "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS test.create_chunks.md --to html4 --from gfm+tex_math_dollars --output test.create_chunks.html --embed-resources --standalone --highlight-style pygments --template "D:\RCompile\CRANpkg\lib\4.6\rmarkdown\rmarkdown\templates\github_document\resources\preview.html" --variable "github-markdown-css:D:\RCompile\CRANpkg\lib\4.6\rmarkdown\rmarkdown\templates\github_document\resources\github.css" --metadata pagetitle=PREVIEW --mathjax Preview created: test.create_chunks.html Output created: test.create_chunks.md > > # Clean up -------------- > file.remove("test.create_chunks.Rmd","test.create_chunks.RDS", + "test.create_chunks.md","test.create_chunks.html") [1] TRUE TRUE TRUE TRUE > unlink("test.create_chunks_files",recursive=TRUE) > > setwd(owd) > > proc.time() user system elapsed 0.73 0.14 1.65