Base R Essentials - Part I

Some essentials Base R functions still important to know in the Tidyverse ecosystem (Help & Objects)

R
Base
Author

Abdoul ISSA BIDA

Published

February 11, 2023

Well, what motivates me to write this series of blog posts is a tweet I saw a few weeks ago, before I went to bed, about what makes an R Developer.

Yes I usually take a daily drop of news from the bird site before to fall into the arms of Morpheus.

Guess I don’t need to paint you all the comments that this tweet has sparked between people who agree with this view and those who think that it is a dumb claim especially coming from an educator.

Before I share my stance on this with you, I have tried from that moment, as a tidyverse aficionado, to summarize all the base R features that I use daily or have used in the past, which I still feel useful in the ecosystem of tidyverse packages.

I have drawn greatly by a cheat sheet written in french by Mayeul KAUFMANN, however I added a bench of base R functions, operators and tricks I encountered while improving my R skills.

This first post is about HELP and OBJECTS DECLARATION and how to access them using R console and specific functions.

Functions Tasks / Examples
help(topic) documentation about topic
?topic also documentation about topic
help.search("topic") searches in help for documentation matching topic
apropos("use*.tidy.*") all objects names corresponding to regular expression use.*tidy.*
help.start() HTML version of the help
example(function) runs the example given for the function at bottom of help page.
Ex: example("cut")
<-, -> arrows for expressions assignations. And yes, arrows can be considered as functions. The variables assignation is done in the arrow direction.
Ex: a <- 2 b <- a b -> c -> d
str(a) object structure
Ex: str(a) where a is an object
summary(a) statistical summary of an object, the results vary according to the argument object class. For a characters string, it returns the length, the class and the mode. For a numeric array it return the min,the max, the 1st quarter, the median, the 3rd quarter … etc.
ls() lists all objects defined in the environment
rm(x) removes the objects named by character vector x
ls.str() lists all objects defined in the environment and for each object, it returns its structure
dir() lists the files in current directory
methods(class=class(a)) lists all methods to deal with objects of the class of object a
library(x) loads package x
library(help=x) lists available datasets and functions in package x.
Ex: library(help="ggplot2")
attach(x) adds the content of x in R search list. So you can find it with search() function. x can be a list, a data frame or an R data file.
detach(x) does the opposite. It removes the content of x from the search list.
q() close R. I don’t think you will quit your session often with that but it is useful to know that you can do it that way.

This list is exhaustive but it is a good start. I will add to it as I learn more. Now let’s move on to part 2 on writing/reading from a file.

Citation

BibTeX citation:
@online{issabida2023,
  author = {Abdoul ISSA BIDA},
  title = {Base {R} {Essentials} - {Part} {I}},
  date = {2023-02-11},
  url = {https://www.abdoulblog.com},
  langid = {en}
}
For attribution, please cite this work as:
Abdoul ISSA BIDA. 2023. “Base R Essentials - Part I.” February 11, 2023. https://www.abdoulblog.com.