Can't use Rcpp engine in R Markdown

大憨熊 提交于 2019-12-01 16:50:38

With the requested information of the Sys.getenv['PATH'] not containing a path with Rtools in it and the knowledge that the knitr error is being triggered by an invalid engine path, I think you are falling victim to devtools::find_rtools() throwing a false positive on setup.

This is typically the case since if it is unable to find Rtools on the system path, it scans for Rtools within the registry and then sets an environment flag. The environment flag does not typically persist while running rmarkdown or during the package build stage. Also see: Why do I need to run find_rtools() before has_devel() = TRUE?

E.g. If you close all open session R sessions, then open a new R session and only type Rcpp::evalCpp("2 + 2") you will likely trigger a compile error.

The fix for this is simple: Add the Rtools install location to the PATH system variable. I maintain an installation guide that literally takes you step-by-step through this process here: http://thecoatlessprofessor.com/programming/rcpp/install-rtools-for-rcpp/

As of Rtools 3.4, the two locations that must be added to the PATH are:

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

To modify your PATH variable on windows see either:

I experienced this error today on windows 10, and the outputs you included are as good as identical to those of mine.

Neither J_F's workaround or adding "c:\Rtools\bin" to paths through advanced system settings solved it.

What solved it for me was to uninstall Rtools and reinstall it, checking the option to change the 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" in there.

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

A workaround could be this:

---
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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!