–
Its been a while since I write a CRAN package and this weekend I decidedto work on a idea I had some time ago. The result is packagePkgsFromFiles
.
When working with different computers at home or work, one of theproblems I have is installing missing packages across differentcomputers. As an example, a script that works in my work computer maynot work in my home computer. This is specially annoying when I have afresh install of the operating system or R. In this case, I mustmanually install all packages, case by case. Instead of focusing on thescript at hand, I spend considerable time finding and installing missingpackages. When using laptops for teaching R, many times I had to waitfor the installation of a package before continuing the class. With mynew package, PkgsFromFiles, I can scan any folder of my computer andinstall all necessary packages before using them, as we will soonlearn.
One of the available solutions to this problem is to use packagepacman. It includesfunction p_load
that will check if a package is available and, if not,install it from CRAN. However, for me, I like using library
andrequire
as it is consistent with my code format. Also, in a fresh Rinstall, I rather install all my required packages in a single run sothat I don’t have to wait later.
Package PkgsFromFiles solves this issue by finding and parsing all Rrelated files (.R, .Rmd, .Rnw) from a given folder. It finds all callsto library() and require() and installs all packages that are notavailable locally.
1 |
|
The main function of the package is pff_find_and_install_pkgs
, whichwill search and install missing packages from R files at a givendirectory. As an example, we’ll use my research folder from Dropbox. Itcontains all R script I have ever used in my research work. Let’s try itout:
1 |
|
As you can see, function pff_find_and_install_pkgs
will find all Rrelated files recursively in the given folder. In this case, I have allpackages locally so no installation was required. A summary in text isshown at the end of execution.
The output of the function is a dataframe with the details of theoperation. Have a look:
1 |
|
The package also includes function pff_find_R_files_from_folder
, whichwill find all packages used in R related files from a given folder. Itoutputs a dataframe with several information about packages used in thefound scripts.
1 |
|
I also wrote a simple function for plotting the most used packages for agiven folder:
1 |
|
As you can see, I’m a big fan of the tidyverse
!
Hope you guys find the package useful! Fell free to send any question tothe comment section of the post or my email ([email protected]).
Related