Compiling PDF from a .rnw file in RStudio gets error in function getSymbols()

I'm trying to compile a .Rnw file and I am getting errors in the output pdf, the thing is that if I execute in RStudio all the code chunks one by one it works perfectly, but when I try to compile the pdf an error is printed in the output pdf.

## Error in getSymbols("FB", scr = "yahoo", from = "2015-01-01", to = "2015-12-31"): Could not find function getSymbols()

In my document, before the chunk where I use the function getSymbols(), i have a require(quantmod) that does not gives any error. In fact as I said before if I execute each chunk one by one it works.

Here I let you the outputs of Sys.which('pdflatex') and sessionInfo() for further Information.

> Sys.which('pdflatex')
           pdflatex 
"/usr/bin/pdflatex" 
> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=es_ES.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=es_ES.UTF-8    
 [5] LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=es_ES.UTF-8    LC_PAPER=es_ES.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xtable_1.8-2    ggplot2_2.2.1   dplyr_0.7.4     quantmod_0.4-12 TTR_0.23-2      xts_0.10-1     
[7] zoo_1.8-0      

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14     bindr_0.1        magrittr_1.5     munsell_0.4.3    colorspace_1.3-2 lattice_0.20-35 
 [7] R6_2.2.2         rlang_0.1.6      plyr_1.8.4       tools_3.4.3      grid_3.4.3       gtable_0.2.0    
[13] lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.1     bindrcpp_0.2     curl_3.1         glue_1.2.0      
[19] labeling_0.3     compiler_3.4.3   pillar_1.0.1     scales_0.5.0     pkgconfig_2.0.1 

Hope you can help me!!


require(quantmod) will return FALSE if it can't load quantmod , it won't generate an error. If you want to see an error, use library(quantmod) .

The most likely cause of the problem is that RStudio is using a different library of packages than the child session that is processing your document. You may be able to diagnose this by printing the results of .libPaths() in the console in RStudio and in an early chunk of your document, and seeing what the differences are. sessionInfo() in the document will tell you if it is running a different R version.

BTW, this is probably just a typo in your question, but the getSymbols argument is src , not scr .

链接地址: http://www.djcxy.com/p/33440.html

上一篇: 更改由rmarkdown生成的PDF中的字体

下一篇: 在RStudio中编译.rnw文件中的PDF会在getSymbols()函数中出错