Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



20200501 A command is a function (Section 3.5) for which we are generally more interested in the actions or side-effects that are performed by the command rather than the value returned by the command. For example, the base::library() command is run to attach a package from the library (the action) and consequently modifies the search path that R uses to find commands (the side-effect).
# Load package from the local library into the R session.


A command is also a function and does in fact return a value. In the above example we do not see any value printed. Functions in R can be implemented to return values invisibly. This is the case for base::library(). We can ask R to print the value when the returned result is invisible using the function base::print().

# Demonstrate that library() returns a value invisibly.

##  [1] "rattle"    "bitops"    "extrafont" "forcats"   "stringr"   "dplyr"...
##  [7] "purrr"     "readr"     "tidyr"     "tibble"    "tidyverse" "Hmisc"...
## [13] "ggplot2"   "Formula"   "survival"  "lattice"   "magrittr"  "xtable...
## [19] "knitr"     "stats"     "graphics"  "grDevices" "utils"     "datase...
## [25] "methods"   "base"

We see that the value returned by base::library() is a vector of character strings. Each character string names a package that has been attached during this session of R. Notice that the vector begins with item [1] and then item [5] continues on the second line, and so on. We can save the resulting vector into a variable (Section 3.18) and then index the variable to identify packages at specific locations within the vector.

# Load a package and save the value returned.

l <- library(rattle)

# Review one of the returned values.

## [1] "purrr"

Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.