As a Data Scientist, we have to use multiple tools such as R, python, SQL,etc., while using these tools we don’t always remember the obscurely named functions. By using pacman we can solve this problem. Pacman package is basically a R package management tool. It provides intuitively named functions for the base functions. It also integrates the functionality of the multiple functions to perform multiple tasks in single command. In this vignette we will go through some of the functions of pacman package.
To install packman follow the steps given below.
STEP 1: Open RStudio and start a new project.
Figure 2.1 - New Project
STEP 2: Start a new script.
Figure 2.2 - New script
STEP 3: Execute the following command.
install.packages(“pacman”)
STEP 4: Make sure pacman package is installed.
Figure 2.2 - Console
STEP 5: Load the pacman package.
The format of the function names in pacman package is p_XXX. ‘XXX’ is the task that the function performs. Now we will look into some of the commonly used functions.
p_load()
p_load() is used to load required packages that are already installed or install it first and then load if not locally available. This makes it really helpful for forums and blog posts as it will install and load any missing packages on the reader’s computer. This function is a great substitute for the functions library() and require(). We can save a lot of time by executing a single line of p_load() instead of executing multiple lines of library() function. This is demonstrated in the following example.
Example:
library(tidyverse)
#> -- Attaching packages ------------------------------------------- tidyverse 1.3.0 --
#> v ggplot2 3.3.0 v purrr 0.3.3
#> v tibble 2.1.3 v dplyr 0.8.5
#> v tidyr 1.0.2 v stringr 1.4.0
#> v readr 1.3.1 v forcats 0.5.0
#> -- Conflicts ---------------------------------------------- tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
library(stringr)
library(httr)
library(jsonlite)
#>
#> Attaching package: 'jsonlite'
#> The following object is masked from 'package:purrr':
#>
#> flatten
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> datep_load_gh()
Most of us struggle while accessing the repositories in github. But pacman package makes that easier. By using the function p_load_gh() we can install and load the github packages easily.
Example:
p_install_version()
Sometimes the user needs the minimal version of a package installed that’s when this function is used. This function is useful in blog posts where a new package is being demonstrated.
Example:
p_funs()
If you need to print all the available functions in a particular package then this function is used.
Example:
p_funs(ggplot2)
#> [1] "%+%" "%+replace%"
#> [3] ".data" ".pt"
#> [5] ".stroke" "aes"
#> [7] "aes_" "aes_all"
#> [9] "aes_auto" "aes_q"
#> [11] "aes_string" "after_scale"
#> [13] "after_stat" "alpha"
#> [15] "annotate" "annotation_custom"
#> [17] "annotation_logticks" "annotation_map"
#> [19] "annotation_raster" "arrow"
#> [21] "as_labeller" "autolayer"
#> [23] "autoplot" "AxisSecondary"
#> [25] "benchplot" "borders"
#> [27] "calc_element" "combine_vars"
#> [29] "continuous_scale" "Coord"
#> [31] "coord_cartesian" "coord_equal"
#> [33] "coord_fixed" "coord_flip"
#> [35] "coord_map" "coord_munch"
#> [37] "coord_polar" "coord_quickmap"
#> [39] "coord_sf" "coord_trans"
#> [41] "CoordCartesian" "CoordFixed"
#> [43] "CoordFlip" "CoordMap"
#> [45] "CoordPolar" "CoordQuickmap"
#> [47] "CoordSf" "CoordTrans"
#> [49] "cut_interval" "cut_number"
#> [51] "cut_width" "derive"
#> [53] "discrete_scale" "draw_key_abline"
#> [55] "draw_key_blank" "draw_key_boxplot"
#> [57] "draw_key_crossbar" "draw_key_dotplot"
#> [59] "draw_key_label" "draw_key_path"
#> [61] "draw_key_point" "draw_key_pointrange"
#> [63] "draw_key_polygon" "draw_key_rect"
#> [65] "draw_key_smooth" "draw_key_text"
#> [67] "draw_key_timeseries" "draw_key_vline"
#> [69] "draw_key_vpath" "dup_axis"
#> [71] "el_def" "element_blank"
#> [73] "element_grob" "element_line"
#> [75] "element_rect" "element_render"
#> [77] "element_text" "enexpr"
#> [79] "enexprs" "enquo"
#> [81] "enquos" "ensym"
#> [83] "ensyms" "expand_limits"
#> [85] "expand_scale" "expansion"
#> [87] "expr" "Facet"
#> [89] "facet_grid" "facet_null"
#> [91] "facet_wrap" "FacetGrid"
#> [93] "FacetNull" "FacetWrap"
#> [95] "find_panel" "flip_data"
#> [97] "flipped_names" "fortify"
#> [99] "Geom" "geom_abline"
#> [101] "geom_area" "geom_bar"
#> [103] "geom_bin2d" "geom_blank"
#> [105] "geom_boxplot" "geom_col"
#> [107] "geom_contour" "geom_contour_filled"
#> [109] "geom_count" "geom_crossbar"
#> [111] "geom_curve" "geom_density"
#> [113] "geom_density_2d" "geom_density2d"
#> [115] "geom_dotplot" "geom_errorbar"
#> [117] "geom_errorbarh" "geom_freqpoly"
#> [119] "geom_hex" "geom_histogram"
#> [121] "geom_hline" "geom_jitter"
#> [123] "geom_label" "geom_line"
#> [125] "geom_linerange" "geom_map"
#> [127] "geom_path" "geom_point"
#> [129] "geom_pointrange" "geom_polygon"
#> [131] "geom_qq" "geom_qq_line"
#> [133] "geom_quantile" "geom_raster"
#> [135] "geom_rect" "geom_ribbon"
#> [137] "geom_rug" "geom_segment"
#> [139] "geom_sf" "geom_sf_label"
#> [141] "geom_sf_text" "geom_smooth"
#> [143] "geom_spoke" "geom_step"
#> [145] "geom_text" "geom_tile"
#> [147] "geom_violin" "geom_vline"
#> [149] "GeomAbline" "GeomAnnotationMap"
#> [151] "GeomArea" "GeomBar"
#> [153] "GeomBlank" "GeomBoxplot"
#> [155] "GeomCol" "GeomContour"
#> [157] "GeomCrossbar" "GeomCurve"
#> [159] "GeomCustomAnn" "GeomDensity"
#> [161] "GeomDensity2d" "GeomDotplot"
#> [163] "GeomErrorbar" "GeomErrorbarh"
#> [165] "GeomHex" "GeomHline"
#> [167] "GeomLabel" "GeomLine"
#> [169] "GeomLinerange" "GeomLogticks"
#> [171] "GeomMap" "GeomPath"
#> [173] "GeomPoint" "GeomPointrange"
#> [175] "GeomPolygon" "GeomQuantile"
#> [177] "GeomRaster" "GeomRasterAnn"
#> [179] "GeomRect" "GeomRibbon"
#> [181] "GeomRug" "GeomSegment"
#> [183] "GeomSf" "GeomSmooth"
#> [185] "GeomSpoke" "GeomStep"
#> [187] "GeomText" "GeomTile"
#> [189] "GeomViolin" "GeomVline"
#> [191] "get_element_tree" "gg_dep"
#> [193] "ggplot" "ggplot_add"
#> [195] "ggplot_build" "ggplot_gtable"
#> [197] "ggplotGrob" "ggproto"
#> [199] "ggproto_parent" "ggsave"
#> [201] "ggtitle" "guide_axis"
#> [203] "guide_bins" "guide_colorbar"
#> [205] "guide_colorsteps" "guide_colourbar"
#> [207] "guide_coloursteps" "guide_gengrob"
#> [209] "guide_geom" "guide_legend"
#> [211] "guide_merge" "guide_none"
#> [213] "guide_train" "guide_transform"
#> [215] "guides" "has_flipped_aes"
#> [217] "is.Coord" "is.facet"
#> [219] "is.ggplot" "is.ggproto"
#> [221] "is.theme" "label_both"
#> [223] "label_bquote" "label_context"
#> [225] "label_parsed" "label_value"
#> [227] "label_wrap_gen" "labeller"
#> [229] "labs" "last_plot"
#> [231] "layer" "layer_data"
#> [233] "layer_grob" "layer_scales"
#> [235] "layer_sf" "Layout"
#> [237] "lims" "map_data"
#> [239] "margin" "max_height"
#> [241] "max_width" "mean_cl_boot"
#> [243] "mean_cl_normal" "mean_sdl"
#> [245] "mean_se" "median_hilow"
#> [247] "merge_element" "panel_cols"
#> [249] "panel_rows" "Position"
#> [251] "position_dodge" "position_dodge2"
#> [253] "position_fill" "position_identity"
#> [255] "position_jitter" "position_jitterdodge"
#> [257] "position_nudge" "position_stack"
#> [259] "PositionDodge" "PositionDodge2"
#> [261] "PositionFill" "PositionIdentity"
#> [263] "PositionJitter" "PositionJitterdodge"
#> [265] "PositionNudge" "PositionStack"
#> [267] "qplot" "quickplot"
#> [269] "quo" "quo_name"
#> [271] "quos" "register_theme_elements"
#> [273] "rel" "remove_missing"
#> [275] "render_axes" "render_strips"
#> [277] "reset_theme_settings" "resolution"
#> [279] "Scale" "scale_alpha"
#> [281] "scale_alpha_continuous" "scale_alpha_date"
#> [283] "scale_alpha_datetime" "scale_alpha_discrete"
#> [285] "scale_alpha_identity" "scale_alpha_manual"
#> [287] "scale_alpha_ordinal" "scale_color_binned"
#> [289] "scale_color_brewer" "scale_color_continuous"
#> [291] "scale_color_date" "scale_color_datetime"
#> [293] "scale_color_discrete" "scale_color_distiller"
#> [295] "scale_color_fermenter" "scale_color_gradient"
#> [297] "scale_color_gradient2" "scale_color_gradientn"
#> [299] "scale_color_grey" "scale_color_hue"
#> [301] "scale_color_identity" "scale_color_manual"
#> [303] "scale_color_ordinal" "scale_color_steps"
#> [305] "scale_color_steps2" "scale_color_stepsn"
#> [307] "scale_color_viridis_c" "scale_color_viridis_d"
#> [309] "scale_colour_binned" "scale_colour_brewer"
#> [311] "scale_colour_continuous" "scale_colour_date"
#> [313] "scale_colour_datetime" "scale_colour_discrete"
#> [315] "scale_colour_distiller" "scale_colour_fermenter"
#> [317] "scale_colour_gradient" "scale_colour_gradient2"
#> [319] "scale_colour_gradientn" "scale_colour_grey"
#> [321] "scale_colour_hue" "scale_colour_identity"
#> [323] "scale_colour_manual" "scale_colour_ordinal"
#> [325] "scale_colour_steps" "scale_colour_steps2"
#> [327] "scale_colour_stepsn" "scale_colour_viridis_b"
#> [329] "scale_colour_viridis_c" "scale_colour_viridis_d"
#> [331] "scale_continuous_identity" "scale_discrete_identity"
#> [333] "scale_discrete_manual" "scale_fill_binned"
#> [335] "scale_fill_brewer" "scale_fill_continuous"
#> [337] "scale_fill_date" "scale_fill_datetime"
#> [339] "scale_fill_discrete" "scale_fill_distiller"
#> [341] "scale_fill_fermenter" "scale_fill_gradient"
#> [343] "scale_fill_gradient2" "scale_fill_gradientn"
#> [345] "scale_fill_grey" "scale_fill_hue"
#> [347] "scale_fill_identity" "scale_fill_manual"
#> [349] "scale_fill_ordinal" "scale_fill_steps"
#> [351] "scale_fill_steps2" "scale_fill_stepsn"
#> [353] "scale_fill_viridis_b" "scale_fill_viridis_c"
#> [355] "scale_fill_viridis_d" "scale_linetype"
#> [357] "scale_linetype_binned" "scale_linetype_continuous"
#> [359] "scale_linetype_discrete" "scale_linetype_identity"
#> [361] "scale_linetype_manual" "scale_radius"
#> [363] "scale_shape" "scale_shape_binned"
#> [365] "scale_shape_continuous" "scale_shape_discrete"
#> [367] "scale_shape_identity" "scale_shape_manual"
#> [369] "scale_shape_ordinal" "scale_size"
#> [371] "scale_size_area" "scale_size_binned"
#> [373] "scale_size_binned_area" "scale_size_continuous"
#> [375] "scale_size_date" "scale_size_datetime"
#> [377] "scale_size_discrete" "scale_size_identity"
#> [379] "scale_size_manual" "scale_size_ordinal"
#> [381] "scale_type" "scale_x_binned"
#> [383] "scale_x_continuous" "scale_x_date"
#> [385] "scale_x_datetime" "scale_x_discrete"
#> [387] "scale_x_log10" "scale_x_reverse"
#> [389] "scale_x_sqrt" "scale_x_time"
#> [391] "scale_y_binned" "scale_y_continuous"
#> [393] "scale_y_date" "scale_y_datetime"
#> [395] "scale_y_discrete" "scale_y_log10"
#> [397] "scale_y_reverse" "scale_y_sqrt"
#> [399] "scale_y_time" "ScaleBinned"
#> [401] "ScaleBinnedPosition" "ScaleContinuous"
#> [403] "ScaleContinuousDate" "ScaleContinuousDatetime"
#> [405] "ScaleContinuousIdentity" "ScaleContinuousPosition"
#> [407] "ScaleDiscrete" "ScaleDiscreteIdentity"
#> [409] "ScaleDiscretePosition" "sec_axis"
#> [411] "set_last_plot" "should_stop"
#> [413] "stage" "standardise_aes_names"
#> [415] "stat" "Stat"
#> [417] "stat_bin" "stat_bin_2d"
#> [419] "stat_bin_hex" "stat_bin2d"
#> [421] "stat_binhex" "stat_boxplot"
#> [423] "stat_contour" "stat_contour_filled"
#> [425] "stat_count" "stat_density"
#> [427] "stat_density_2d" "stat_density2d"
#> [429] "stat_ecdf" "stat_ellipse"
#> [431] "stat_function" "stat_identity"
#> [433] "stat_qq" "stat_qq_line"
#> [435] "stat_quantile" "stat_sf"
#> [437] "stat_sf_coordinates" "stat_smooth"
#> [439] "stat_spoke" "stat_sum"
#> [441] "stat_summary" "stat_summary_2d"
#> [443] "stat_summary_bin" "stat_summary_hex"
#> [445] "stat_summary2d" "stat_unique"
#> [447] "stat_ydensity" "StatBin"
#> [449] "StatBin2d" "StatBindot"
#> [451] "StatBinhex" "StatBoxplot"
#> [453] "StatContour" "StatContourFilled"
#> [455] "StatCount" "StatDensity"
#> [457] "StatDensity2d" "StatEcdf"
#> [459] "StatEllipse" "StatFunction"
#> [461] "StatIdentity" "StatQq"
#> [463] "StatQqLine" "StatQuantile"
#> [465] "StatSf" "StatSfCoordinates"
#> [467] "StatSmooth" "StatSum"
#> [469] "StatSummary" "StatSummary2d"
#> [471] "StatSummaryBin" "StatSummaryHex"
#> [473] "StatUnique" "StatYdensity"
#> [475] "summarise_coord" "summarise_layers"
#> [477] "summarise_layout" "sym"
#> [479] "syms" "theme"
#> [481] "theme_bw" "theme_classic"
#> [483] "theme_dark" "theme_get"
#> [485] "theme_gray" "theme_grey"
#> [487] "theme_light" "theme_linedraw"
#> [489] "theme_minimal" "theme_replace"
#> [491] "theme_set" "theme_test"
#> [493] "theme_update" "theme_void"
#> [495] "transform_position" "unit"
#> [497] "update_geom_defaults" "update_labels"
#> [499] "update_stat_defaults" "vars"
#> [501] "waiver" "wrap_dims"
#> [503] "xlab" "xlim"
#> [505] "ylab" "ylim"
#> [507] "zeroGrob"p_detectOS()
This function attempts to detect the operating system of the machine. The command returns the output as “windows”, “Linux” or “Darwin” for mac.
Example:
p_info()
If user needs the information about a particular package then this function is used. The information includes package name, package version, Title, Description of the package and the name of the author.
Example:
p_info(pacman)
#> Package: pacman
#> Type: Package
#> Title: Package Management Tool
#> Version: 0.5.1
#> Authors@R: c(person("Tyler", "Rinker", role = c("aut", "cre", "ctb"),
#> email = "tyler.rinker@gmail.com"), person("Dason",
#> "Kurkiewicz", role = c("aut", "ctb"), email =
#> "dasonk@gmail.com"), person("Keith", "Hughitt", role =
#> c("ctb")), person("Albert", "Wang", role = c("ctb")),
#> person("Garrick", "Aden-Buie", role = c("ctb")),
#> person("Albert", "Wang", role = c("ctb")), person("Lukas",
#> "Burk", role = c("ctb")))
#> Depends: R (>= 3.5.0)
#> Imports: remotes, methods, stats, utils
#> Suggests: BiocManager, knitr, lattice, testthat (>= 0.9.0), XML
#> BugReports: https://github.com/trinker/pacman/issues?state=open
#> Description: Tools to more conveniently perform tasks associated with
#> add-on packages. pacman conveniently wraps library and package
#> related functions and names them in an intuitive and consistent
#> fashion. It seeks to combine functionality from lower level
#> functions which can speed up workflow.
#> License: GPL-2
#> URL: https://github.com/trinker/pacman
#> RoxygenNote: 6.1.1
#> NeedsCompilation: no
#> Packaged: 2019-03-11 01:37:03 UTC; trinker
#> Author: Tyler Rinker [aut, cre, ctb], Dason Kurkiewicz [aut, ctb],
#> Keith Hughitt [ctb], Albert Wang [ctb], Garrick Aden-Buie
#> [ctb], Albert Wang [ctb], Lukas Burk [ctb]
#> Maintainer: Tyler Rinker <tyler.rinker@gmail.com>
#> Repository: CRAN
#> Date/Publication: 2019-03-11 11:50:07 UTC
#> Built: R 3.6.3; ; 2020-04-02 17:08:49 UTC; windows
#>
#> -- File: C:/Users/Yogesh/Documents/R/win-library/3.6/pacman/Meta/package.rds
# You can also get specific information about the package as well.
p_info(corrplot, Author, Version, URL)
#> Warning in utils::packageDescription(package): no package 'corrplot' was found
#> NULLp_install()
This function is used if user only wants to install a package and not load it.
Example:
p_install(vioplot)
#> Installing package into 'C:/Users/Yogesh/Documents/R/win-library/3.6'
#> (as 'lib' is unspecified)
#> Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.6:
#> cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.6/PACKAGES'
#> package 'vioplot' successfully unpacked and MD5 sums checked
#>
#> The downloaded binary packages are in
#> C:\Users\Yogesh\AppData\Local\Temp\RtmpIZBCkv\downloaded_packages
#>
#> vioplot installedp_delete()
Instead of using remove.packages() for every package, we want to delete we can use p_delete() to delete multiple packages in a single command.
Example:
p_delete(vioplot,corrplot)
#> The following packages not found in library:
#> corrplot
#> The following packages have been deleted:
#> vioplotp_help()
This function generates an html, web or PDF of the package’s help manual.
Example:
p_temp()
p_temp() allows the user to install a package temporarily without tempering with the library of the user.
Example:
p_temp(testthat)
#> Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.6:
#> cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.6/PACKAGES'
#> package 'testthat' successfully unpacked and MD5 sums checked
#>
#> The downloaded binary packages are in
#> C:\Users\Yogesh\AppData\Local\Temp\RtmpIZBCkv\downloaded_packages
#>
#> testthat installedThe packman package is used to load required libraries without the need of being sure of having that particular package installed. The functions in this package are easier to use than their equivalent base functions. Coding time required is significantly reduced because of this package.