Unable to use Rcpp engine in R Markdown

I tried Knit HTML following Rmd file:

 --- title: "Untitled" author: "Florian Privé" date: "12 septembre 2016" output: html_document --- ```{r fibCpp, engine='Rcpp'} #include <Rcpp.h> // [[Rcpp::export]] int fibonacci(const int x) { if (x == 0 || x == 1) return(x); return (fibonacci(x - 1)) + fibonacci(x - 2); } ``` 

I got the following error:

 Building shared library for Rcpp code chunk... Warning message: l'exécution de la commande 'make -f "C:/PROGRA~1/R/R-33~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_2.dll" WIN=64 TCLBIN=64 OBJECTS="file110c1d4643e9.o"' renvoie un statut 127 Quitting from lines 11-18 (test.Rmd) Error in (function (file = "", code = NULL, env = globalenv(), embeddedR = TRUE, : Error 1 occurred building shared library. Calls: <Anonymous> ... block_exec -> in_dir -> engine -> do.call -> <Anonymous> Exécution arrêtée 

Am I doing something obviously wrong? Is this a Windows related issue?

Environmental information from sessionInfo()

 R version 3.3.1 (2016-06-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] magrittr_1.5 rsconnect_0.4.3 htmltools_0.3.5 tools_3.3.1 yaml_2.1.13 [6] Rcpp_0.12.7 stringi_1.1.1 rmarkdown_1.0 stringr_1.1.0 digest_0.6.10 [11] evaluate_0.9 

Verifying Rtools installation via devtools::find_rtools()

 [1] TRUE 

Sys.getenv()['PATH'] Results Sys.getenv()['PATH']

 ## PATH C:\Program ## Files\R\R-3.3.1\bin\x64;C:\ProgramData\Oracle\Java\javapath;C:\Program ## Files\NVIDIA GPU Computing ## Toolkit\CUDA\v7.5\bin;C:\Program ## Files\NVIDIA GPU Computing ## Toolkit\CUDA\v7.5\libnvvp;;C:\Program Files ## (x86)\Intel\iCLS Client\;C:\Program ## Files\Intel\iCLS ## Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program ## Files (x86)\Windows Live\Shared;C:\Program ## Files\Intel\Intel(R) Management Engine ## Components\DAL;C:\Program ## Files\Intel\Intel(R) Management Engine ## Components\IPT;C:\Program Files ## (x86)\Intel\Intel(R) Management Engine ## Components\DAL;C:\Program Files ## (x86)\Intel\Intel(R) Management Engine ## Components\IPT;C:\Program Files ## (x86)\Skype\Phone\;C:\Users\Florian\.dnx\bin;C:\Program ## Files\Microsoft DNX\Dnvm\;C:\Program Files ## (x86)\NVIDIA ## Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Florian\Anaconda3;C:\Users\Florian\Anaconda3\Scripts;C:\Users\Florian\Anaconda3\Library\bin;C:\Program ## Files ## (x86)\Java\jre1.8.0_101\bin\client;C:\texlive\2015\bin\win32 
+7
r knitr rcpp devtools r-markdown
source share
3 answers

With the requested information Sys.getenv['PATH'] that does not contain the path with Rtools in it and the knowledge that the knitr error is triggered by an invalid engine, I think that you become a victim of devtools :: find_rtools () , setting a false positive during configuration .

This is usually the case, because if he cannot find Rtools on the way to the system, he scans Rtools in the registry and then sets the environment flag. The environment flag is usually not saved when rmarkdown starts or during the package build phase. Also see: Why do I need to run find_rtools () before has_devel () = TRUE?

eg. If you close all sessions of an open R session, open a new R session and enter the type Rcpp::evalCpp("2 + 2") , which is most likely to cause a compilation error.

The fix for this is simple: Add Rtools installation location to the PATH system variable. I support the installation guide, which literally takes a step by step in this process: http://thecoatlessprofessor.com/programming/rcpp/install-rtools-for-rcpp/

As in Rtools 3.4, the two places that should be added to PATH are as follows:

 c:\Rtools\bin; c:\Rtools\mingw_32\bin; 

To change your PATH variable in windows, follow these steps:

+4
source share

Today I encountered this error in Windows 10, and you turned on outputs similar to mine.

Neither the J_F workaround, nor the addition of "c: \ Rtools \ bin" to the paths through the advanced system settings resolved.

For me, it was decided to remove Rtools and reinstall it, checking the possibility of changing paths during installation. I put the paths: "c: \ Rtools \ bin", "C: \ Rtools \ mingw_32 \ bin", "C: \ Program Files \ R \ R-3.3.1 \ bin \ i386" and "C: \ Program Files \ R \ R-3.3.1 \ bin \ x64 "there.

I wonder why adding "c: \ Rtools \ bin" to paths through advanced system settings did not change the output of Sys.getenv()['PATH']

+1
source share

The workaround may be as follows:

 --- title: "Untitled" author: "Florian Privé" date: "12 septembre 2016" output: html_document --- ```{r} Rcpp::cppFunction(' int fibonacci(const int x) { if (x == 0 || x == 1) return(x); return (fibonacci(x - 1)) + fibonacci(x - 2); }') ``` ```{r} fibonacci(10L) ``` # [1] 55 
0
source share

All Articles