Common Uncommon Notations that Confuse New R Coders

April 17, 2019
By

(This article was first published on R – William Doane, and kindly contributed to R-bloggers)

Here are a few of the more commonly used notations found in R code and documentation that confuse coders of any skill level who are new to R.

Be aware that any variable name that begins with a . is usually hidden from view, so won’t be seen in the Environment pane in RStudio or listed when you invoke

  ls()

unless you specify

  ls(all.names = TRUE)

Notation Meaning
. This is a variable name. It’s often found in association with the magrittr pipe operator %>% and is the name used to denote the otherwise anonymous object being passed in from the left-hand side (LHS). You typically see it used when you need to pass the piped object in to base-R or other non-tidyverse functions. Normally, tidyverse functions are written to accept a data object as their first parameter and the pipe operator passes the result of the LHS implicitly as the first argument, but base-R functions might expect the data object in any parameter position.
... Known as “dot-dot-dot”, “ellipses”, or “three dots”—difficult to search for, unless you know those names for it. This is another variable name. It can only be used as a formal parameter to a function and is often simply passed along to other functions called from within that function. It’s a way of coding the intention that “at coding time, we don’t know what additional arguments or how many may be passed in, so we’re just going to accept any number of additional arguments.” You can choose to parse them yourself and make use of them or simply pass them on to other functions you invoke within your function.
.x Often used as a generic variable name for any type of object: see purrr::map.
.f Often used as a generic variable name for a function object: see purrr::map.
.data Often used as a generic variable name for a data.frame object, especially when being used as the first parameter to a function written to play nicely in the tidyverse: see dplyr::select.
df This could mean “degrees of freedom”, but it’s also often used as a mnemonic generic variable name for a data.frame object, when you don’t yet know a better, more descriptive name to use. Consider it the “this could be any data.frame” name for a data.frame. It’s often found in early iterations of exploratory code and in example code. You should use more intention revealing variable names, when you can.
.Last.value The is the variable name R automatically associates with the most recently evaluated object. Usually hidden, RStudio has an option to make it visible in your Environment pane: Tools > Global options… > General > Advanced > Show .Last.value in environment listing

To leave a comment for the author, please follow the link and comment on their blog: R – William Doane.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)