search & searchpaths Functions in R (2 Examples)
In this R tutorial you’ll learn how to apply the search and searchpaths functions.
The tutorial consists of two examples for the application of the search and searchpaths functions. To be more precise, the article contains these content blocks:
With that, let’s just jump right in…
Example 1: Applying the search() Function in R
Example 1 illustrates how to apply the search function in R.
The search command returns a list of attached packages and objects.
Have a look at the following R code and its output:
search() # Using search() # [1] ".GlobalEnv" "package:xlsx" "package:wordcloud" # [4] "package:shadowtext" "package:shinythemes" "package:rdrop2" # [7] "package:raster" "package:sp" "package:qdapRegex" # [10] "package:png" "package:patchwork" "package:stringr" # [13] "package:RColorBrewer" "package:plyr" "package:officer" # [16] "package:magrittr" "package:magick" "package:gtools" # [19] "package:gtable" "package:gridExtra" "package:grid" # [22] "package:googlesheets4" "package:googledrive" "package:ggplot2" # [25] "package:evaluate" "package:dplyr" "package:Cairo" # [28] "package:shiny" "package:stats" "package:graphics" # [31] "package:grDevices" "package:utils" "package:datasets" # [34] "package:methods" "Autoloads" "package:base"
Example 2: Applying the searchpaths() Function in R
Similar to the search function, we can use the searchpaths function to extract a list of all paths to attached packages and data objects:
searchpaths() # Using searchpaths() # [1] ".GlobalEnv" # [2] "C:/Users/Joach/Documents/R/win-library/4.1/xlsx" # [3] "C:/Users/Joach/Documents/R/win-library/4.1/wordcloud" # [4] "C:/Users/Joach/Documents/R/win-library/4.1/shadowtext" # [5] "C:/Users/Joach/Documents/R/win-library/4.1/shinythemes" # [6] "C:/Users/Joach/Documents/R/win-library/4.1/shiny" # [7] "C:/Users/Joach/Documents/R/win-library/4.1/rdrop2" # [8] "C:/Users/Joach/Documents/R/win-library/4.1/raster" # [9] "C:/Users/Joach/Documents/R/win-library/4.1/sp" # [10] "C:/Users/Joach/Documents/R/win-library/4.1/qdapRegex" # [11] "C:/Users/Joach/Documents/R/win-library/4.1/png" # [12] "C:/Users/Joach/Documents/R/win-library/4.1/patchwork" # [13] "C:/Users/Joach/Documents/R/win-library/4.1/stringr" # [14] "C:/Users/Joach/Documents/R/win-library/4.1/RColorBrewer" # [15] "C:/Users/Joach/Documents/R/win-library/4.1/plyr" # [16] "C:/Users/Joach/Documents/R/win-library/4.1/officer" # [17] "C:/Users/Joach/Documents/R/win-library/4.1/magrittr" # [18] "C:/Users/Joach/Documents/R/win-library/4.1/magick" # [19] "C:/Users/Joach/Documents/R/win-library/4.1/gtools" # [20] "C:/Users/Joach/Documents/R/win-library/4.1/gtable" # [21] "C:/Program Files/R/R-4.1.0/library/grid" # [22] "C:/Users/Joach/Documents/R/win-library/4.1/googlesheets4" # [23] "C:/Users/Joach/Documents/R/win-library/4.1/googledrive" # [24] "C:/Users/Joach/Documents/R/win-library/4.1/evaluate" # [25] "C:/Users/Joach/Documents/R/win-library/4.1/dplyr" # [26] "C:/Users/Joach/Documents/R/win-library/4.1/Cairo" # [27] "C:/Users/Joach/Documents/R/win-library/4.1/RGoogleAnalytics" # [28] "C:/Users/Joach/Documents/R/win-library/4.1/digest" # [29] "C:/Users/Joach/Documents/R/win-library/4.1/httr" # [30] "C:/Users/Joach/Documents/R/win-library/4.1/lubridate" # [31] "C:/Users/Joach/Documents/R/win-library/4.1/gridExtra" # [32] "C:/Users/Joach/Documents/R/win-library/4.1/ggplot2" # [33] "tools:rstudio" # [34] "C:/Program Files/R/R-4.1.0/library/stats" # [35] "C:/Program Files/R/R-4.1.0/library/graphics" # [36] "C:/Program Files/R/R-4.1.0/library/grDevices" # [37] "C:/Program Files/R/R-4.1.0/library/utils" # [38] "C:/Program Files/R/R-4.1.0/library/datasets" # [39] "C:/Program Files/R/R-4.1.0/library/methods" # [40] "Autoloads" # [41] "C:/PROGRA~1/R/R-41~1.0/library/base"
As you can see, the path elements of the previous list correspond to the attached packages and objects of Example 1.
Video & Further Resources
Have a look at the following video on the Statistics Globe YouTube channel. In the video, I’m explaining the R programming syntax of this article.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
In addition, you may have a look at the related R tutorials that I have published on this website. Some articles are listed below.
In this tutorial, I have explained how to use the search and searchpaths functions in the R programming language. If you have additional questions, please let me know in the comments section.
Statistics Globe Newsletter