I am unable to render Rmarkdown documents with Rscript if they have dplyr SQLite calls in them. Take this MWE (test.Rmd) which calls for a table in a local copy of the dplyr::lahman_sqlite() table.
---
title: "TestFile"
output: html_document
---
```{r setup, include=FALSE}
library(dplyr)
lahman <- src_sqlite("lahman.sqlite")
```
```{r}
tbl(lahman, "Batting")
```
In a live R console session I can call rmarkdown::render("test.Rmd"), and this document is built as expected. But if I call Rscript -e 'rmarkdown::render("test.Rmd")' on the command line, I get the following error:
Quitting from lines 12-13 (test.Rmd)
Error in UseMethod("db_query_fields") :
no applicable method for 'db_query_fields' applied to an object of class "SQLiteConnection"
Calls: render ... make_tbl -> structure -> op_base_remote -> db_query_fields
I've attached my sessionInfo below, but I've duplicated this error on OS X as well as Ubuntu.
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin15.5.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.5.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 digest_0.6.9 assertthat_0.1 R6_2.1.2 DBI_0.4-1 formatR_1.4 magrittr_1.5 evaluate_0.9
[9] RSQLite_1.0.0 stringi_1.1.1 rmarkdown_0.9.6 tools_3.3.1 stringr_1.0.0 Lahman_4.0-1 yaml_2.1.13 htmltools_0.3.5
[17] knitr_1.13 tibble_1.0
The problem comes from the fact that when using Rscript the methods package is not loaded. It's therefore required to load it explicitly by adding library(methods) in the setup chunk for instance.
Related
I'm trying to prepare an Rmarkdown file for a course. But for some reason (perhaps a very, very dumb reason) I can't seem to knit anything. Here is a very simple example of an Rmarkdown script:
---
title: "big data"
author: "CAM"
date: "21 March 2020"
output:
html_document: default
---
```{r,chunk1,eval=TRUE,echo=TRUE,include=TRUE}
seq(1,10,by=1)
```
This throws the error:
Error in parse(text = x, keep.source = TRUE) :
attempt to use zero-length variable name
Calls: <Anonymous> -> <Anonymous> -> getParseData -> parse
Execution halted
The code itself executes in the chunk, but it won't knit.
Here is my session info. (I just moved to catalina on mac, maybe there's a problem here).
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.3
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] knitr_1.28 rmarkdown_2.1
loaded via a namespace (and not attached):
[1] compiler_3.6.3 htmltools_0.4.0 tools_3.6.3
[4] yaml_2.2.1 Rcpp_1.0.3 xfun_0.12
[7] digest_0.6.25 rlang_0.4.5 evaluate_0.14
Found the answer. It's has to be saved as a .Rmd file, not an .R file. This is the case even if you selected your script as a Rmarkdown file within RStudio.
When trying to Preview a simple notebook in RStudio, I am getting the following error in the top of the source pane and no nb.html file is created:
"Error creating notebook: no lines available in input"
Screenshot:
> sessionInfo(package = NULL)
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 LC_MONETARY=German_Austria.1252 LC_NUMERIC=C LC_TIME=German_Austria.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.6 tools_3.3.3 base64enc_0.1-3 yaml_2.1.14 Rcpp_0.12.12 stringi_1.1.3 rmarkdown_1.8 knitr_1.17
[12] stringr_1.2.0 digest_0.6.12 evaluate_0.10
> RStudio.Version()
$mode
[1] "desktop"
$version
[1] ‘1.0.153’
I wasn't able to replicate the exact error but you could try writing the output html notebook in same line.
---
title: "R Notebook"
output: html_notebook: default
html_document: default
---
I fixed this by opening a new Notebook, copying the contents of my original, error-ing Notebook there, and then overwriting the original Notebook. The error presented, for me, after I moved a folder containing all the files associated with this project to a new location.
When I knit to HTML, images show up fine in the .html file, but not the .nb.html one. MWE is the R Notebook template: the plot(cars) image does not show.
Per suggestions listed here: RStudio notebook does not show data.frames when I compile, I tried older/newer/dev versions of rmarkdown. I also tried newer/dev versions of knitr. Nothing helped. I have RStudio version 1.0.136.
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X Yosemite 10.10.5
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.12.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.8 withr_1.0.2 digest_0.6.11 rprojroot_1.2 R6_2.2.0
[6] jsonlite_1.2 backports_1.0.5 git2r_0.15.0 magrittr_1.5 evaluate_0.10
[11] highr_0.6 httr_1.2.1 stringi_1.1.2 curl_2.3 rstudioapi_0.6
[16] rmarkdown_1.3 tools_3.3.2 stringr_1.1.0 yaml_2.1.14 rsconnect_0.7
[21] base64enc_0.1-3 memoise_1.0.0 htmltools_0.3.5 knitr_1.15.8
Thanks to RStudio for pointing out that this is expected behavior. I had switched the chunk output setting to Chunk Output in Console so I could view plots in the plot window. I didn't realize that all chunks must be run inline to appear in the notebook. I switched back to Chunk Output Inline, ran the chunks, and all was well.
I am unable to compile a Rmd as pdf with the CrossTable example from the "Using pander with knitr" vignette.
Here is my code
---
title: "Pander CrossTable test"
author: "Christiaan Pauw"
date: "08 March 2016"
output: pdf_document
---
```{r }
library(pander)
library(descr, quietly = TRUE)
pander(CrossTable(mtcars$gear, mtcars$cyl))
```
The error message reads:
output file: Untitled.knit.md
! LaTeX Error: There's no line here to end.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.159 ~\\15\\\\
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
Execution halted
Here is my session info
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] descr_1.1.2 pander_0.6.0 ggplot2_2.0.0 reshape2_1.4.1 stargazer_5.2 raster_2.5-2
[7] Matrix_1.2-3 sp_1.2-1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.3 knitr_1.12.3 magrittr_1.5 munsell_0.4.2 colorspace_1.2-6
[6] xtable_1.8-0 lattice_0.20-33 stringr_1.0.0 plyr_1.8.3 tools_3.2.3
[11] grid_3.2.3 gtable_0.1.2 htmltools_0.3 yaml_2.1.13 digest_0.6.9
[16] rmarkdown_0.9.5.1 stringi_1.0-1 scales_0.3.0
For the record: The problem seemed to solve itself. When I returned to this problem after a few updates everything worked
It works for R version 3.3.0 with Rstudio Version 0.99.902. The pandoc version is 1.15.2
I have a trouble with Rsutdio and knitr in Windows 7 for rendering a simple gvisTable. Here is my code
```{r results='asis'}
require(googleVis)
op <- options(gvis.plot.tag="chart")
data(iris)
t = gvisTable(data = iris)
print(t)
```
and here is my error :
pandoc.exe: Failed to retrieve https://www.google.com/jsapi?callback=displayChartTableID14c4345d7f3
FailedConnectionException2 "www.google.com" 443 True connect: failed (Connection timed out (WSAETIMEDOUT))
Erreur : pandoc document conversion failed with error 61
My Rstudio version is : 0.98.1091
And my SessionInfo is :
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotrix_3.5-10 data.table_1.9.4 googleVis_0.5.6 knitr_1.8
loaded via a namespace (and not attached):
[1] chron_2.3-45 digest_0.6.4 evaluate_0.5.5 formatR_1.0 htmltools_0.2.6 plyr_1.8.1 Rcpp_0.11.3
[8] reshape2_1.4 RJSONIO_1.3-0 rmarkdown_0.3.11 stringr_0.6.2 tools_3.1.2 yaml_2.1.13
or this code works perfectly fine :
```{r results='asis'}
require(knitr)
data(iris)
kable(iris)
```
Do you have any idea of the problem with googleVis in this context ? Thanks in advance for any help.
Pandoc is trying to download the googleVis chart so that it can embed a static/offline copy in your document. You can work around the problem by telling Pandoc not to create a standalone document (i.e. don't do the resource embedding that's causing the problem)--add this to the top of your document, or just the text between --- if you already have a YAML header:
---
output:
html_document:
self_contained: no
---
Pandoc shouldn't have a problem fetching resources over https. If you have time to repro the problem outside the rmarkdown workflow (i.e. on a vanilla Markdown -> HTML conversion) and find that it's still an issue, please file an issue for Pandoc: https://github.com/jgm/pandoc/issues.