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) > > # Create lots of data to insert into doc ------------------ > x = runif(3e5) > y = 4*x + 3 + rnorm(3e5) > > d = data.frame(x=x,y=y) > rds.fn = "test.large_data_chunk.RDS" > saveRDS(d,rds.fn) > > # ~3.7 MB of data > # Rstudio won't open a file larger than 5 MB... > # But render always works... > > # Create Rmarkdown doc -------------- > library(knitrdata) > library(magrittr) # For pipe operator > > # Create new Rmarkdown document > rmd.fn = "test.large_data_chunk.Rmd" > if (file.exists(rmd.fn)) + file.remove(rmd.fn) > rmarkdown::draft(rmd.fn,"github_document","rmarkdown",edit=FALSE) > > # Create chunks ------------------ > > loadlib = create_chunk("library(knitrdata)",chunk_type="r",chunk_label="loadlib") > loaddata = data_encode( + rds.fn,"base64", + options=list(linewidth=300)) %>% # Make lines longer to help with visualization + create_chunk(output.var="d",format="binary",loader.function=readRDS, + echo=TRUE, # Test max.echo option of knitrdata + chunk_label="loaddata") > analyzedata = create_chunk("summary(lm(y~x,data=d))",chunk_type="r",chunk_label="analyzedata") > > # Push chunks into document ------------------ > > # Insert in reverse order to not have to figure out line number > rmd.text = readLines(rmd.fn) > > rmd.text = insert_chunk(analyzedata,11,rmd.text=rmd.text) > rmd.text = insert_chunk(loaddata,11,rmd.text=rmd.text) > rmd.text = insert_chunk(loadlib,11,rmd.text=rmd.text) > > writeLines(rmd.text,rmd.fn) > > # List all chunks in document > chunklst = list_rmd_chunks(file=rmd.fn) > chunklst type label start end 1 r setup 6 8 2 r loadlib 11 13 3 data loaddata 14 17151 4 r analyzedata 17152 17154 5 r cars 17162 17164 6 r pressure 17170 17172 > > # View file in Rstudio ---------- > # rstudioapi::navigateToFile(rmd.fn) > > # Rstudio will warn about file size and will take some time to open it, > # but it does eventually work. If you collapse down the visualization > # of the data chunk, then moving around and editing the documents works > # rapidly without any problems. > > # Render document to test ------- > if (rmarkdown::pandoc_available(version="1.12.3")) + system.time( + rmarkdown::render(rmd.fn) + ) processing file: test.large_data_chunk.Rmd output file: test.large_data_chunk.knit.md "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS test.large_data_chunk.knit.md --to gfm+tex_math_dollars-yaml_metadata_block --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.large_data_chunk.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.large_data_chunk.md --to html4 --from gfm+tex_math_dollars --output test.large_data_chunk.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.large_data_chunk.html Output created: test.large_data_chunk.md user system elapsed 2.16 0.11 2.88 > > # Clean up -------------- > file.remove(rmd.fn,rds.fn, + sub("[.][^.]+$",".md",rmd.fn),sub("[.][^.]+$",".html",rmd.fn)) [1] TRUE TRUE TRUE TRUE > unlink(sub("[.][^.]+$","_files",rmd.fn),recursive=TRUE) > > setwd(owd) > > proc.time() user system elapsed 3.87 0.45 5.15