blog/an-efficient-way-to-install-and-load-r-packages/ #81
Replies: 22 comments 3 replies
-
Comment written by Gillberke on February 01, 2020 10:04:23: It is not possible to use |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on February 01, 2020 15:50:28: Thanks for your comment Gillberke. Yes it is possible to put the invisible function before, like this:
And I actually believe it is even better to put it that way because the pipe I edited the article by including your comment. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Comment written by jameshunterbr on February 02, 2020 21:42:18: Like pacman, the librarian package will try to install packages not yet installed in its shelf function (equivalent of library). It also searches in bioconductor and github for the package to load. |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on February 03, 2020 08:07:13: Thanks for your comment James, I have edited the article according to it! |
Beta Was this translation helpful? Give feedback.
-
Comment written by Philip Gundy on February 04, 2020 19:39:38: I actually have been using something very similar, however instead of invisible I use the below code and I also reverse the package order list to correctly have packages mask functions in my preferred order. I find the way this ends up printing into the console is quite helpful.
|
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on February 05, 2020 09:08:51: Thanks for your comment Philip! Many users will find your code useful too, depending on their preferences :) |
Beta Was this translation helpful? Give feedback.
-
Comment written by Alan Haynes on February 05, 2020 14:06:37: You could also check out renv (its essentially a replacement for pacman as far as I understand it). It'll sift through all of your code looking various ways of loading/using a package and make a lockfile containing details of package versions and, where necessary, a local package library. Makes it easy to revert changes if you update a package and break something... (it doesn't, however, play nicely with your "more efficient" way of loading packages, it only recognizes methods such as library(x), x::, x:::, etc). You don't need to then include install.packages in the script, just do it manually once and then renv will pull it if its actually needed for the analysis. |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on February 06, 2020 15:22:05: Thanks Alan for your comment, I'll definitely check it out! |
Beta Was this translation helpful? Give feedback.
-
Comment written by Matt.0 on February 11, 2020 21:35:26: {renv} is a good suggestion for managing environments (replacement for {packrat}) put out by RStudio team (https://github.com/rstudio/renv) but already mentioned by Alan Haynes. If you're just looking for a more efficient way to install packages then the R-lib team has a package called {pak} which (I believe) is a replacement for {pacman}. It installs R packages from multiple sources CRAN/Bioconductor/Github (https://github.com/r-lib/pak)) which is convenient and claims to be faster and safer |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on February 11, 2020 22:48:20: Thanks Matt for your input. As you are the second person to recommend the |
Beta Was this translation helpful? Give feedback.
-
Comment written by Aaron D. Cherniak on October 11, 2020 14:31:41: How do I know that librarian was set? Nothing appears in the console when I run the line. |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on October 11, 2020 16:22:37: Dear Aaron, The best way to check that everything is set is by simply running a function from the package you wanted to install and load. So for example, if you wanted to install and load the
And then try to create a plot with the Hope this helps. Regards, |
Beta Was this translation helpful? Give feedback.
-
Hello. How can I load the package only if it's not already loaded? This can be useful for example when running script files, changing something and running it again... |
Beta Was this translation helpful? Give feedback.
-
Hello, The code in this section and the Unfortunately, I am not aware of any function or code which also checks that a package is already loaded before loading it. However, from my personal experience (which may be different than yours depending on the number of packages you use), I see that installing packages takes time, but loading them (even if they have already been loaded) does not take much time. Does that take a long time on your side? If yes, perhaps a workaround would be to edit my code so that it only loads the one not already loaded. But I don't have any quick/easy solution. Hope this helps. Regards, |
Beta Was this translation helpful? Give feedback.
-
Maybe the way is using a setdiff with the list of needed packages and the output of (.packages()) |
Beta Was this translation helpful? Give feedback.
-
Good question. I'm not an expert in packages management so I cannot answer your question. If you feel it, feel free to give it a try and let me know if it works! Regards, |
Beta Was this translation helpful? Give feedback.
-
Most efficient way {pacman} package After this article was published, a reader informed me about the {packman} package <- ### minor edit here: packman -> pacman |
Beta Was this translation helpful? Give feedback.
-
Corrected. Thank you Ashish! |
Beta Was this translation helpful? Give feedback.
-
In fact I think it was me :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for this post and the comments, |
Beta Was this translation helpful? Give feedback.
-
Dear Jens, Thanks for your comment. Unfortunately I am not familiar with Good luck in your research! Regards, |
Beta Was this translation helpful? Give feedback.
-
Hi, I am new to R, may I ask why running the code lapply(Mypakage-name, library, character.only = TRUE) and I got an error is: Could you please guide me how to solve this problem? Very thanks! |
Beta Was this translation helpful? Give feedback.
-
An efficient way to install and load R packages - Stats and R
What are R packages and how to use them? Discover also a more efficient way to install and load R packages in R thanks to the pacman and librarian packages
https://statsandr.com/blog/an-efficient-way-to-install-and-load-r-packages/
Beta Was this translation helpful? Give feedback.
All reactions