RStudio doesn't find rmarkdown package when knitting

I have a working R Markdown script but when I try to knit it, R Markdown gives the following error:
Error in loadNamespace(name) : there is no package called 'rmarkdown'
Calls: :: ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted

The package is installed, I tried removing and reinstalling it but got the same error.
The package is listed in installed.packages().

I should maybe add that I edited my Rprofile because I wasn't happy with the default location for packages (inspired by this post):
myPaths <- .libPaths()
myPaths <- myPaths[2]

Is R Markdown maybe looking for the package in the old directory?

Also, I'm using the most recent versions of R (3.6.0) and RStudio (1.2.1335).

Every help is appreciated, thank you!

1 Like

@Rricarda How are you trying to knit the file? Are you clicking on the RStudio Knit button?

What happens if you try running the command directly in the R console where you were running installed.packages(), e.g.


Thanks! Knitting through the console indeed works :slight_smile:

1 Like

@Rricarda Great! I'm glad that worked.

The RStudio Knit button should also work though. Where is your .Rprofile saved? The line below checks if it is saved in your user directory (if you're on Windows it will be in Documents).


Also, have you tried setting the environment variable R_LIBS_USER to your preferred library location? I think that may be a more robust solution to your problem (and easier to read). For example, if you create the file ~/.Renviron and add the line R_LIBS_USER="/path/to/my/preferred/location", the first path in .libPaths() will be that preferred path.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.