Finding and Installing Packages Used in R and RMarkdown Files

Includes functions for finding and installing used R packages from local scripts and Rmarkdown files.

When working with different computers at home or work, one of the problems I have is installing missing packages in R. As an example, a script that works in my work computer may not work in my home computer if a particular package is not installed. This is specially annoying when I have a fresh install of the operating system. In this case I must manualy install all packages, case by case.

One of the solutions to this problem is to use package pacman. It includes function p_load that will check if a package is available and, if not, install it from CRAN. However, for me, I like using library and require as it is consistent with my code format. Also, in a fresh R install, I rather install all my required packages in a single run, before I need it.

Package PkgsFromFiles solves this issue by finding and parsing all R related files (.R, .Rmd, .Rnw) from a given folder, finding all calls to library() and require() and installing all unavailable packages.


# from cran 
# from github
if (!require(devtools)) install.packages('devtools')


The main function of the package is pff_find_and_install_pkgs, which will search and install missing packages from R files at a given directory. As an example, we'll use the folder from the package, which contains two example scripts. Let's try it out:

my.dir <- dirname(system.file('extdata', package = 'PkgsFromFiles'))
df <- pff_find_and_install_pkgs( = my.dir)

As you can see, function pff_find_and_install_pkgs will find all R related files recursivelly in the given folder. A summary in text is shown at the end of execution.

The output of the function is a dataframe with the details of the operation:


The package also includes function pff_plot_summary_pkgs:

p <- pff_plot_summary_pkgs( = my.dir)


Version 0.5 (2018-10-13)

First version

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.5 by Marcelo Perlin, 7 months ago

Report a bug at

Browse source code at

Authors: Marcelo Perlin [aut, cre]

Documentation:   PDF Manual  

GPL-2 license

Imports stringr, XML, dplyr, readr, stringdist, curl

Suggests knitr, rmarkdown, testthat, ggplot2

See at CRAN