简体   繁体   English

knitr 无法识别 r 代码块

[英]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:我正在使用以下代码块在 Markdown 文件中的 R-Studio(使用 MacOS 10.10.3)中测试 knitr:

```{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.但是,在 R-Console 中键入summary(cars)会产生预期的输出。 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''警告:命名空间“评估”不可用,处理对象时已被 .GlobalEnv 替换“”

1- Root Cause : package "evaluate" was not properly installed, so remove it and install again : 1-根本原因:未正确安装包“评估”,因此将其删除并重新安装:

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

install.packages("evaluate") install.packages("评估")

2- so when I tried to load the package evaluate ,I started getting below error: 2-所以当我尝试加载包评估时,我开始收到以下错误:

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' library("evaluate", lib.loc="~/R/win-library/3.2") loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) 错误:没有名为“stringi”的包此外:警告消息:包“评估”是在 R 版本 3.2.5 下构建的错误:“评估”的包或命名空间加载失败

3- I installed the package "stringi" again and problem was resolved. 3- 我再次安装了“stringi”包,问题解决了。 :) :)

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).通过切换到运行 Mac OS X 10.9.5(使用 RStudio 0.98.1103 和 Tex Live 10/29/13 版本)的 MacAir 笔记本电脑,我能够解决上述问题。 With this setup, the test program shown above and my more elaborate mtcars analysis program ran smooth as silk!有了这个设置,上面显示的测试程序和我更精细的 mtcars 分析程序运行顺利! 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.在我不知情的情况下,Mac OS Yosemite 10.10.3(在我的桌面 Mac 上)和 knitr(或 Tex Live)似乎有些不兼容。 Interestingly, I tried simple in-line r code such as {r} 1+1 and this worked fine.有趣的是,我尝试了简单的内嵌 r 代码,例如{r} 1+1并且效果很好。

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!不知何故,从我上次使用我的 RMD 文件到刚刚打开它,除了几行代码之外,其他所有代码都被从行的开头“制表”了,这使得 R 无法识别我的代码块!

If you select all and do "shift+tab" until everything is moved completely to the left, it should work again.如果您全选并执行“shift+tab”,直到所有内容都完全向左移动,它应该会再次工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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