pacman
package in R. In order to use the
functions that are contained in the pacman
package, we have
to install and load the package to R:install.packages("pacman") # Install pacman package
library("pacman") # Load pacman package
pacman
package.In this example, I will illustrate how to apply the p_load function to load multiple add-on packages in one line of code.
Have a look at the following R syntax:
p_load(dplyr, stringr) # Install & load packages
After executing the previous code, we have loaded the packages
dplyr
, and stringr
.
Note that the p_load function also checks whether a package is
installed already. If the package is not installed yet, it is installed
automatically by the pacman
package.
Another useful function of the pacman
package is the
p_unload function. The p_unload function can be used to detach one or
multiple loaded packages from within R.
Let’s apply the p_unload command to unload the packages
dplyr
, and stringr
that we have loaded
before:
p_unload(dplyr, stringr) # Unload packages
dplyr
,
stringr
The previous output of the RStudio console tells us
that our three packages were detached.In this example, I will show how to use the p_update function of
the pacman
package to check for outdated packages AND to
update all of these packages.
First, let’s check which of my packages are outdated:
p_update(update = FALSE) # Check for outdated packages
Second, the pacman
package provides an easy solution
to how we can update all outdated packages with only one line of R
code.
Make sure that you have some time before running the following R code. This may take some time, depending on the number of packages you need to update:
p_update() # Update all packages
install.packages("devtools")
devtools::install_cran("MASS")
install.packages("remotes")
remotes::install_github("r-lib/conflicted")
install.packages("stargazer")
# Load your external dataset
data(mtcars)
# Check the summary of dataset
summary(mtcars)
# Create summary statistics table using stargazer
stargazer(mtcars, type='text', title='Summary Statistics')
# Fit regression model
fit <- lm(mpg ~ wt + cyl, data = mtcars)
# Create table that summarizes the new regression model
stargazer(fit, type = 'text', title = 'Regression Summary Table',
out = 'C:\\Users\\Downloads\\R.txt')
readxl
from CRAN:install.packages("readxl")
xlsx_example <- readxl_example("datasets.xlsx")
read_excel(xlsx_example)
excel_sheets(xlsx_example)
read_excel(xlsx_example, sheet = "chickwts")
read_excel(xls_example, sheet = 4)
here()
uses a reasonable heuristics to find your
project’s files, based on the current working directory at the time when
the package is loaded. Use it as a drop-in replacement for file.path(),
it will always locate the files relative to your project root.install.packages("here")
here("data", "penguins.csv")
rvest
is a package that makes it easy to scrape (or
harvest) data from html web pages.install.packages("rvest")
html <- read_html("https://en.wikipedia.org/w/index.php?title=The_Lego_Movie&oldid=998422565")
html %>%
html_element(".tracklist") %>%
html_table()
install.packages('ggthemes')
ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
colour = factor(gear))) + theme_base() + ggtitle("theme_base()")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point() +
theme_calc() +
ggtitle("theme_calc()")
install.packages("ggpubr")
ggdensity(wdata, x = "weight",
add = "mean", rug = TRUE,
color = "sex", fill = "sex",
palette = c("#00AFBB", "#E7B800"))
install.packages("plotly")
fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
fig
install.packages("tidyverse")
install.packages("stringr")
install.packages("bibliometrix")
install.packages("remotes")
remotes::install_github("massimoaria/bibliometrix")
Updated on: 2025-02-13