Running 'test.create_chunks.R' [1s]
  Running 'test.csv_rds_chunks.R' [1s]
  Running 'test.data_encode_decode.R' [1s]
  Running 'test.large_data_chunk.R' [3s]
  Running 'test.md5sum_chunks.R' [1s]
Running the tests in 'tests/test.create_chunks.R' failed.
Complete output:
  > # 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")
  Error: only `math_method = 'mathjax'` is supported with earlier version than Pandoc 2.0 
  Execution halted
Running the tests in 'tests/test.csv_rds_chunks.R' failed.
Complete output:
  > library(knitrdata)
  > library(magrittr) # For pipe operator
  > 
  > # Use a temporary directory ----------------------------
  > owd = getwd()
  > td = tempdir()
  > setwd(td)
  > 
  > # Create simple data files ------------------
  > df = data.frame(a=letters[1:3],b=1.1:3.1)
  > 
  > csv.fn = "test.csv_rds_chunks.csv"
  > csv2.fn = "test.csv_rds_chunks.csv2"
  > odd.fn = "test.csv_rds_chunks.odd"
  > rds.fn = "test.csv_rds_chunks.RDS"
  > 
  > write.csv(df,csv.fn,row.names=FALSE)
  > write.csv2(df,csv2.fn,row.names=FALSE)
  > write.table(df,odd.fn,row.names=FALSE,sep="|",dec=":")
  > saveRDS(df,rds.fn)
  > 
  > # Create chunks ------------------
  > loadlib = create_chunk("library(knitrdata)",chunk_type="r",chunk_label="loadlib")
  > 
  > lines = readLines(csv.fn)
  > lines2 = readLines(csv2.fn)
  > lines3 = readLines(odd.fn)
  > 
  > loadcsv =
  +   create_chunk(lines,output.var="df.csv",echo=TRUE,chunk_label="loadcsv",chunk_type="csv")
  > loadcsv2 =
  +   create_chunk(lines2,output.var="df.csv2",echo=TRUE,chunk_label="loadcsv2",chunk_type="csv2")
  > loadodd =
  +   create_chunk(lines3,output.var="df.odd",echo=TRUE,
  +                sep="|",dec=":",chunk_label="loadodd",chunk_type="csv")
  > 
  > loadrds = data_encode(rds.fn,"base64") %>%
  +   create_chunk(output.var="df.rds",echo=TRUE,chunk_label="loadrds",chunk_type="rds")
  > 
  > showdata = create_chunk(c("df.csv","df.csv","df.odd","df.rds"),
  +                         chunk_type="r",
  +                         chunk_label="showdata")
  > 
  > # Create Rmarkdown doc --------------
  > rmd.fn = "test.csv_rds_chunks.Rmd"
  > if (file.exists(rmd.fn))
  +   file.remove(rmd.fn)
  > rmarkdown::draft(rmd.fn,"github_document","rmarkdown",edit=FALSE)
  > 
  > # 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(showdata,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadrds,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadodd,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadcsv2,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadcsv,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  csv  loadcsv    14  19
  4 csv2 loadcsv2    20  25
  5  csv  loadodd    26  31
  6  rds  loadrds    32  37
  7    r showdata    38  43
  8    r     cars    51  53
  9    r pressure    59  61
  > 
  > # View file in Rstudio ----------
  > # rstudioapi::navigateToFile(rmd.fn)
  > 
  > # Clean environment ------
  > l = ls()
  > l = l[!(l %in% c("rmd.fn","owd"))]
  > rm(list=l)
  > 
  > # Render document to test -------
  > if (rmarkdown::pandoc_available(version="1.12.3"))
  +   system.time(
  +     rmarkdown::render(rmd.fn)
  +   )
  Error: only `math_method = 'mathjax'` is supported with earlier version than Pandoc 2.0 
  Timing stopped at: 0.02 0 0.02
  Execution halted
Running the tests in 'tests/test.large_data_chunk.R' failed.
Complete output:
  > # 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)
  +   )
  Error: only `math_method = 'mathjax'` is supported with earlier version than Pandoc 2.0 
  Timing stopped at: 0.81 0 0.81
  Execution halted
Running the tests in 'tests/test.md5sum_chunks.R' failed.
Complete output:
  > library(knitrdata)
  > library(magrittr) # For pipe operator
  > 
  > # Use a temporary directory ----------------------------
  > owd = getwd()
  > td = tempdir()
  > setwd(td)
  > 
  > # Create simple text files ------------------
  > 
  > # Text file with platform line separator
  > pn = platform.newline()
  > txt = paste0(pn,"Hello",pn,pn,"Goodbye",pn,pn)
  > txt.fn = "test.md5sum_chunks.txt"
  > writeChar(txt,txt.fn,useBytes=TRUE,eos=NULL)
  > txt.md5 = tools::md5sum(txt.fn)
  > 
  > # Text file with opposite line separator
  > opn = ifelse(pn=="\n","\r\n","\n")
  > txt2 = paste0(opn,"Goodbye",opn,opn,"Hello",opn,opn)
  > txt2.fn = "test2.md5sum_chunks.txt"
  > writeChar(txt2,txt2.fn,useBytes=TRUE,eos=NULL)
  > txt2.md5 = tools::md5sum(txt2.fn)
  > 
  > # Chinese text
  > ch.txt = "åå¨æºæµè°æ¥å"
  > ch.fn = "test.md5sum_chunks.ch.txt"
  > writeLines(ch.txt,ch.fn,useBytes=TRUE)
  > ch.md5 = tools::md5sum(ch.fn)
  > print(ch.md5)
           test.md5sum_chunks.ch.txt 
  "607d4928052edb4f05c83a86c487b8d5" 
  > # MD5 sums of Chinese text do not work on Windows, likely due to character encoding translation issues!!!
  > # This webpage seems pertinent: https://stackoverflow.com/questions/38230026/how-to-print-chinese-letters-from-r
  > 
  > # Create a simple binary file ----------------
  > d = data.frame(x=1:3,y=letters[1:3])
  > rds.fn = "test.md5sum_chunks.RDS"
  > saveRDS(d,rds.fn)
  > rds.md5 = tools::md5sum(rds.fn)
  > 
  > # Create Rmarkdown doc --------------
  > rmd.fn = "test.md5sum_chunks.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")
  > 
  > lines = readLines(txt.fn)
  > lines2 = readLines(txt2.fn)
  > 
  > co = paste0('md5sum="',txt.md5,'"')
  > loadtxt =
  +   create_chunk(lines,output.var="txt",output.file="output.md5sum_chunks.txt",
  +                format="text",echo=TRUE,
  +                chunk_label="loadtxt",chunk_options_string = co
  +   )
  > 
  > # Text chunk specifying explicitly newline character to use
  > oopn = ifelse(opn=="\n","\\n","\\r\\n")
  > co2 = paste0('md5sum="',txt2.md5,'",line.sep="',oopn,'"')
  > loadtxt2 =
  +   create_chunk(lines2,output.var="txt2",output.file="output2.md5sum_chunks.txt",
  +                format="text",echo=TRUE,
  +                chunk_label="loadtxt2",chunk_options_string = co2
  +   )
  > 
  > loadtxt64 = data_encode(txt.fn,"base64") %>%
  +   create_chunk(output.var="txt64",output.file="output.md5sum_chunks.64.txt",
  +                format="text",echo=TRUE,encoding="base64",
  +                chunk_label="loadtxt64",chunk_options_string = co
  +   )
  > 
  > co2 = paste0('md5sum="',txt2.md5,'"')
  > loadtxt264 = data_encode(txt2.fn,"base64") %>%
  +   create_chunk(output.var="txt264",output.file="output2.md5sum_chunks.64.txt",
  +                format="text",echo=TRUE,encoding="base64",
  +                chunk_label="loadtxt264",chunk_options_string = co2
  +   )
  > 
  > co = paste0('md5sum="',rds.md5,'"')
  > loaddata = data_encode(rds.fn,"base64") %>%
  +   create_chunk(output.var="d",output.file="output.md5sum_chunks.RDS",
  +                format="binary",loader.function=readRDS,echo=TRUE,
  +                chunk_label="loadrds",chunk_options_string = co
  +   )
  > 
  > showdata = create_chunk(c("cat(txt)","cat(txt2)","cat(txt64)","cat(txt264)","d"),
  +                         chunk_type="r",
  +                         chunk_label="showdata")
  > 
  > # Chinese text - md5sum test fails on Windows
  > co = paste0('md5sum="',ch.md5,'"')
  > loadch =
  +   create_chunk(file=ch.fn,output.var="chtxt",output.file="output.md5sum_chunks.ch.txt",
  +                format="text",echo=TRUE,
  +                chunk_label="loadchtxt"
  +                #,chunk_options_string = co # MD5 sum fails on Windows
  +   )
  > 
  > showch = create_chunk(c("cat(chtxt)","tools::md5sum('output.md5sum_chunks.ch.txt')"),
  +                         chunk_type="r",
  +                         chunk_label="showch")
  > 
  > # 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(showch,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadch,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(showdata,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loaddata,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadtxt264,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadtxt64,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadtxt2,11,rmd.text=rmd.text)
  > rmd.text = insert_chunk(loadtxt,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    loadtxt    14  20
  4  data   loadtxt2    21  27
  5  data  loadtxt64    28  30
  6  data loadtxt264    31  33
  7  data    loadrds    34  39
  8     r   showdata    40  46
  9  data  loadchtxt    47  49
  10    r     showch    50  53
  11    r       cars    61  63
  12    r   pressure    69  71
  > 
  > # View file in Rstudio ----------
  > # rstudioapi::navigateToFile(rmd.fn)
  > 
  > # Clean environment ------
  > l = ls()
  > l = l[!(l %in% c("rmd.fn","owd"))]
  > rm(list=l)
  > 
  > # Render document to test -------
  > if (rmarkdown::pandoc_available(version="1.12.3")) {
  +   system.time(
  +     rmarkdown::render(rmd.fn)
  +   )
  + 
  +   # Check MD5 sum of Chinese text before and after
  +   print(tools::md5sum('output.md5sum_chunks.ch.txt'))
  + }
  Error: only `math_method = 'mathjax'` is supported with earlier version than Pandoc 2.0 
  Timing stopped at: 0.02 0 0.02
  Execution halted