I often prepare summary tables of statistics that I share at work. The tables often contain the same type of data and column headers (e.g. number of bylaw violations, number of units, etc.). I often work with shorthand column names in R data frames ("nbbldg", "nbunits", "nbvl") or other column names inherited from imported tables. Here's an example:
df <-
data.frame(
DESCRIPTION_TXT_BLW = c(
"Missing plumbing fixture",
"Improperly installed heating unit",
"Loose or damaged siding",
"Peeling paint"
),
DESCR_UNIT = c("Apartment", "Apartment", "Common area", "Common area"),
nbvl = as.integer(c(12, 4, 76, 4))
)
I then translate the column names into their "readable" counterparts before exporting to csv through the following function (example list provided) :
changecolnames<-function (df, codetotext)
{
lapply(names(df), function(x) {
if (x %in% names(codetotext)) {
codetotext[[x]]
}
else {
x
}
})
}
readablecolnames <-
list(
"DESCR_UNIT" = "Description of unit",
"DESCRIPTION_TXT_BLW" = "Description of bylaw violation",
"nbvl" = "Number of bylaw violations"
)
names(df)<-changecolnames(df, readablecolnames)
So far, I have project specific lists which allow to me convert the columns names. I would like to aggregate the disparate lists into a global one accessible from any R project (in RStudio) and keep adding to it. My objective is to avoid creating a list in each project, and instead refer to a sort of easy-to-update master "library". What is the best way of achieving this?