Common Uncommon Notations that Confuse New R Coders
[This article was first published on R – William Doane, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.