简体   繁体   English

将 R_markdown 编织为 PDF 时加载命名空间出错

[英]Error in loadnamespace when knitting R_markdown to PDF

This is the first time I use R_Markdown这是我第一次使用 R_Markdown

I created a new R_Markdown and am trying to knit it to PDF.我创建了一个新的 R_Markdown 并试图将其编织为 PDF。 When I do it I get the following error当我这样做时,我收到以下错误


processing file: R_markdown.Rmd
  |..........                                                            |  14%
  ordinary text without R code

  |....................                                                  |  29%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |..............................                                        |  43%
  ordinary text without R code

  |........................................                              |  57%
label: cars
  |..................................................                    |  71%
  ordinary text without R code

  |............................................................          |  86%
label: pressure (with options) 
List of 1
 $ echo: logi FALSE

  |......................................................................| 100%
  ordinary text without R code


output file: R_markdown.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS R_markdown.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output R_markdown.tex --lua-filter "C:\Users\faiel\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\faiel\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in" 
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  namespace 'xfun' 0.17 is already loaded, but >= 0.19 is required
Calls: <Anonymous> ... namespaceImportFrom -> asNamespace -> loadNamespace
Execution halted

I can't understand why this is happening.我不明白为什么会这样。 I tried the following我尝试了以下

install.packages("rmarkdown")

and

update.packages(ask = FALSE, checkBuilt = TRUE)
tinytex::tlmgr_update()

But without any luck但没有任何运气

Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace 'xfun' 0.17 is already loaded, but >= 0.19 is required loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) 中的错误:命名空间'xfun' 0.17 已加载,但 >= 0.19 是必需的

If you found an error as above you can use the below solution to remove the error.如果您发现上述错误,您可以使用以下解决方案来消除错误。 And the same method can be used for any package.(in place of xfun any package name could be present).同样的方法可以用于任何包。(代替 xfun 任何包名称都可以存在)。

Solution:解决方案:
In RStudio, Navigate to ->Tools->Check For package updates, here you can select the packages and update.在 RStudio 中,导航到 ->Tools->Check For package updates,在这里您可以选择软件包并进行更新。 If this doesn't work update the R version and try updating packages.如果这不起作用,请更新 R 版本并尝试更新软件包。

By performing the above method the package will be updated to a newer version.通过执行上述方法,包将更新到更新的版本。

The version of xfun that's on CRAN is currently 0.18. CRAN 上的xfun版本目前是 0.18。 Apparently you're using some other package that requires xfun version 0.19.显然您正在使用其他一些需要xfun 0.19 版的软件包。 So you need to stop using that non-CRAN package, or update xfun from Github or some other untested source.所以你需要停止使用那个非 CRAN 包,或者从 Github 或其他一些未经测试的源更新xfun

You can run remotes::update_packages() to search lots of places for updates.您可以运行remotes::update_packages()来搜索许多更新的地方。 I don't recommend relying on non-CRAN packages: they may change tomorrow in an incompatible way.我不建议依赖非 CRAN 包:它们明天可能会以不兼容的方式更改。

To find out which non-CRAN packages were installed by the remotes package (or devtools ), you can run要找出remotes包(或devtools )安装了哪些非 CRAN 包,您可以运行

subset(as.data.frame(installed.packages(fields="RemoteType")), !is.na(RemoteType))

However, I don't think that will detect packages that were installed by downloading the .tar.gz or .zip file.但是,我认为这不会检测通过下载.tar.gz.zip文件安装的软件包。 I don't know how to detect those.我不知道如何检测这些。

I have had to same Problem under RStudio 1.4.1103.0 and R 4.0.4 (Win10, 20H2).我在 RStudio 1.4.1103.0 和 R 4.0.4 (Win10, 20H2) 下遇到了同样的问题。 The problem appeared after I updated the installed packages.我更新安装的软件包后出现了问题。 I can't say which ones exactly, because I updated all packages.我不能确切地说是哪些,因为我更新了所有软件包。

Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace 'xfun' 0.17 is already loaded, but >= 0.19 is required

Xfun could not be updated. Xfun 无法更新。 I uninstalled rstudio and then installed the latest version of RStudio (11.04.) and R (4.0.5.) respectively.我卸载了 rstudio,然后分别安装了最新版本的 RStudio (11.04.) 和 R (4.0.5.)。 After that I could update xfun (0.22) again and the problem was solved .之后我可以再次更新 xfun (0.22),问题就解决了

All in all quite time consuming and I didn't quite understand the problem.总而言之,相当耗时,我不太明白这个问题。 Maybe there are better ways?也许有更好的方法?

Eu havia atualizado o R para 4.12 e RStudio 2021.09.1 372 (WIN10 PRO) e apresentou esse erro descrito. Eu havia atualizado o R para 4.12 e RStudio 2021.09.1 372 (WIN10 PRO) e apresentou esse erro descrito。 Então atualizei conforme: No RStudio, acesse -> Ferramentas-> Verificar atualizações de pacote, Atualizei todos os pacotes. Então atualizei Conforme:没有 RStudio,acesse -> Ferramentas-> Verificar atualizações de pacote,Atualizei todos os pacotes。 Pronto funcionou.立即功能。 reiniciei a maquina e rodei o RStudio. reiniciei a maquina e rodei o RStudio。

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

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