I tried to Knit HTML
the following Rmd file:
---
title: \"Untitled\"
author: \"Florian Privé\"
date: \"12 septembre 2016\"
output: html_document
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:
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
I also just experienced this issue. I see that it's been a couple years since this was last addressed, so I wanted to update with the solution that I've found in 2020.
I received that exact error that was mentioned at the top, and had into do a fresh install of Rtools. I originally had RBuildTools, which works for other packages I've built, but still had the issue when compiling the cpp code for this project. I installed Rtools40 and kept all of the defaults. Then changed the system path variable on my windows 10 machine to say C:\rtools40\usr\bin
. After restarting the machine, knitr rendered the document without any further errors.
Rtools40 installation instructions can be found at this link
I hope that this helps!
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']