Best practices for object and data frame naming


#1

For projects that create many data frames and objects in a linear(ish) order, what is the best practice for organization? Is there a better solution than prefixes? Is there an add-in that can tag data frames with metadata + a sortable library?


#2

No there is not, but one thing to consider is that if you have many similar objects you should put them in a list.

So the data frames data2015, data2016 should rather be something like birdsightings <- list("2015" = ..., "2016" = ...). Especially since you mention prefixes, that really sounds like you would rather want a list of data.frames.

You can add attributes or comments to data.frames in base R, but i never found that concept particularly useful (see help on ?attr and ?comment). I prefer to have my objects documented in the scripts that creates them.


#3

Thanks!

I guess (long-term) what I’m imaging is a file explorer similar to an OS. In the Environment window, in addition to the data frame / tibble name and dimensions, there’s additional data including:

  1. Which script file (or in the console) the df was created
  2. The chunk name and/or line number
  3. User notes that are retained when you overwrite the dataframe with one of the same name.

For now, you’re right that lists can be cleaner, especially with the more recent list tools in the tidyverse.