为什么安装 rmarkdown 时会出现此错误

Why do I get this error installing rmarkdown

我尝试使用rmarkdown,但到目前为止我遇到了很多麻烦。第一个是当 Rstudio 好像它应该安装新版本的包时。它不能超过它。我试图一个一个地安装所有必需的包,但我得到了这个错误

 trying URL 'https://cran.rstudio.com/bin/windows/contrib/2.15/knitr_1.5.zip'
Content type 'application/zip' length 910172 bytes (888 Kb)
opened URL
downloaded 888 Kb

package ‘evaluate’ successfully unpacked and MD5 sums checked
package ‘digest’ successfully unpacked and MD5 sums checked
package ‘formatR’ successfully unpacked and MD5 sums checked
package ‘highr’ successfully unpacked and MD5 sums checked
package ‘markdown’ successfully unpacked and MD5 sums checked
package ‘stringr’ successfully unpacked and MD5 sums checked
package ‘knitr’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\mali\AppData\Local\Temp\Rtmpcz1Ywk\downloaded_packages
Error: invalid version specification ‘NA’
In addition: Warning message:
In utils:::packageDescription(packageName, fields = "Version") :
  no package 'knitr' was found

我一个一个地安装了包,我可以加载它们,但它不能作为一个整体工作i.r。文件 -> 新建 -> rmarkdown

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252    LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C                   
[5] LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rmarkdown_0.9.6 knitr_1.12.3   

loaded via a namespace (and not attached):
[1] digest_0.6.9    htmltools_0.3.5 Rcpp_0.12.4     tools_3.1.2 

我最近发现我在启动 Rstudio 时收到了这种消息

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Error: invalid version specification ‘NA’
In addition: Warning message:
In utils:::packageDescription(packageName, fields = "Version") :
  no package 'knitr' was found
> 

我按照@DAV 的建议做了。尝试安装其他版本。没有成功

> url <- "https://cran.r-project.org/src/contrib/Archive/knitr/knitr_1.0.tar.gz"
> install.packages(url, repos=NULL, type="source")
Installing package into ‘\xxx/users/Eke/mali/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/src/contrib/Archive/knitr/knitr_1.0.tar.gz'
Content type 'application/x-gzip' length 451348 bytes (440 Kb)
opened URL
downloaded 440 Kb

* installing *source* package 'knitr' ...
** package 'knitr' successfully unpacked and MD5 sums checked
** R
** demo
** inst
** preparing package for lazy loading
Warning in file(con, "r") :
  file("") only supports open = "w+" and open = "w+b": using the former
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
  there is no package called 'knitr'
Error: loading failed
Execution halted
ERROR: loading failed
* removing '\xxxxxx/users/Eke/mali/Documents/R/win-library/3.1/knitr'
Warning in install.packages :
  running command '"C:/PROGRA~1/R/R-31~1.2/bin/i386/R" CMD INSTALL -l "\xxxxx\users\Eke\mali\Documents\R\win-library.1" "C:/Users/mali/AppData/Local/Temp/RtmpoN1qrM/downloaded_packages/knitr_1.0.tar.gz"' had status 1
Warning in install.packages :
  installation of package ‘C:/Users/mali/AppData/Local/Temp/RtmpoN1qrM/downloaded_packages/knitr_1.0.tar.gz’ had non-zero exit status

这让我发疯。我卸载了 "knitr" 并尝试重新安装。错误

> install.packages("knitr", dependencies = F)
Installing package into ‘\xxxx.se/users/Eke/mali/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.1/knitr_1.12.3.zip'
Content type 'application/zip' length 812186 bytes (793 Kb)
opened URL
downloaded 793 Kb

package ‘knitr’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\mali\AppData\Local\Temp\RtmpaChLQ5\downloaded_packages
Error: invalid version specification ‘NA’
In addition: Warning message:
In utils:::packageDescription(packageName, fields = "Version") :
  no package 'knitr' was found

当我想安装时发生了 shiny

> install.packages("shiny", dependencies = F)
Installing package into ‘\xxxxx.xxx/users/Eke/mali/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.1/shiny_0.13.2.zip'
Content type 'application/zip' length 2257481 bytes (2.2 Mb)
opened URL
downloaded 2.2 Mb

package ‘shiny’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\mali\AppData\Local\Temp\RtmpC0nOFC\downloaded_packages
Error: invalid version specification ‘NA’
In addition: Warning message:
In utils:::packageDescription(packageName, fields = "Version") :
  no package 'knitr' was found

您可以通过 .libPaths() 告诉 RStudio 您的库的位置 命令,然后通过屏幕上的包 window 手动选择 knitr 和使用 RStudio 中的 "rmarkdown" 文档所需的其他包。

getwd()

# "C:/Users/s146753/Dropbox/Chapter 2"

.libPaths()

# "\\home2.bio.ed.ac.uk/s146753/R/win-library/3.3" "C:/Program Files/R/R-3.3.2/library"

.libPaths("C:/Program Files/R/R-3.3.2/library")
.libPaths()

# "C:/Program Files/R/R-3.3.2/library"