4

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

FrAiello
  • 73
  • 1
  • 1
  • 7

4 Answers4

7

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.

ranjan shetty
  • 71
  • 1
  • 3
  • 1
    Ranjan, Welcome to SO! It's nice that you've included a way to use RStudio's GUI to update packages. I think your answer could use a little more depth (e.g. note how @user2554330's answer pinpointed the offending package) so that others who find their way to this answer can clearly see what problem your proposed solution solves and how. – Michael Roswell May 11 '21 at 15:49
0

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.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Thank you. I don't think I have ever installed a non-CRAN package, what would be the best way to check this and use the CRAN's **xfun** ? – FrAiello Nov 05 '20 at 17:53
  • @FrAiello: I've edited my answer to give a partial response. – user2554330 Nov 05 '20 at 19:41
  • 1
    I encountered a similar problem when using R markdown. I got the solution by simply updating the packages in Rstudio. – T Richard Mar 09 '21 at 22:57
0

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?

formatc
  • 35
  • 5
0

Answer from Ranjan Shetty works. https://stackoverflow.com/users/15898034/ranjan-shetty

Just reinstaled xfun package, and issue solved.

(I don't comment because I haven't enough points)

serbuz
  • 43
  • 6
  • Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. - [From Review](/review/late-answers/34088143) – Z.Lin Mar 26 '23 at 12:45