简体   繁体   中英

Error in loadnamespace when knitting R_markdown to PDF

This is the first time I use R_Markdown

I created a new R_Markdown and am trying to knit it to 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

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).

Solution:
In RStudio, Navigate to ->Tools->Check For package updates, here you can select the packages and update. If this doesn't work update the R version and try updating packages.

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. Apparently you're using some other package that requires xfun version 0.19. So you need to stop using that non-CRAN package, or update xfun from Github or some other untested source.

You can run remotes::update_packages() to search lots of places for updates. I don't recommend relying on non-CRAN packages: they may change tomorrow in an incompatible way.

To find out which non-CRAN packages were installed by the remotes package (or devtools ), you can run

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. 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). 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. I uninstalled rstudio and then installed the latest version of RStudio (11.04.) and R (4.0.5.) respectively. After that I could update xfun (0.22) again and the problem was solved .

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. Então atualizei conforme: No RStudio, acesse -> Ferramentas-> Verificar atualizações de pacote, Atualizei todos os pacotes. Pronto funcionou. reiniciei a maquina e rodei o RStudio.

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