简体   繁体   中英

knitr not recognizing r-code chunks

I am testing knitr in R-Studio (with MacOS 10.10.3) in a Markdown file with the following code chunk:

```{r}
summary(cars)
```
The compilation stops with the following message:
processing file: Preview-13c324b5a94e.Rmd
Warning: namespace 'formatR' is not available and has been replaced
by .GlobalEnv when processing object 'silent'

Quitting from lines 13-14 (Preview-13c324b5a94e.Rmd) 
Error in loadNamespace(name) : there is no package called 'evaluate'
Calls: <Anonymous> ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted 

However, typing summary(cars) in the R-Console produces the expected output. I also have tried changing the working directory but no luck.

Any ideas?

I was also having the similar issue with below error :

Warning: namespace 'evaluate' is not available and has been replaced by .GlobalEnv when processing object''

1- Root Cause : package "evaluate" was not properly installed, so remove it and install again :

remove.packages("evaluate", lib="~/R/win-library/3.2")

install.packages("evaluate")

2- so when I tried to load the package evaluate ,I started getting below error:

library("evaluate", lib.loc="~/R/win-library/3.2") Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called 'stringi' In addition: Warning message: package 'evaluate' was built under R version 3.2.5 Error: package or namespace load failed for 'evaluate'

3- I installed the package "stringi" again and problem was resolved. :)

I was able to solve the above problem by switching to my MacAir laptop which runs Mac OS X 10.9.5 (with RStudio 0.98.1103 and Tex Live 10/29/13 version). With this setup, the test program shown above and my more elaborate mtcars analysis program ran smooth as silk! To my uninformed mind, it would seem like Mac OS Yosemite 10.10.3 (on my desktop Mac) and knitr (or Tex Live) have some incompatibility. Interestingly, I tried simple in-line r code such as {r} 1+1 and this worked fine.

Somehow between when I last used my RMD file, and opening it just now, all but a few lines of my code had been "tabbed" away from the start of the line which made R not recognize my code chunks!

If you select all and do "shift+tab" until everything is moved completely to the left, it should work again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM