3.5 Commands
20200501 A command is a function (Section 3.6) 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).
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().
## [1] "readr" "httr" "rattle" "bitops" "tibble" "tidyr"
## [7] "stringr" "knitr" "ggplot2" "dplyr" "magrittr" "stats"
## [13] "graphics" "grDevices" "datasets" "utils" "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.19) 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.
l[7]## [1] "stringr"
If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0