I would like to keep data frame attributes after some joins. It seems that dplyr
functions holds attributes from columns but not the ones from the data frame itself.
See the example below:
library("dplyr")
library("lubridate")
#Fake data
n = 20
df <- data.frame("user_id" = 1:n,
"type" = sample(c(1,2), n, replace = T),
"amount" = 1000*rnorm(n))
#Suppose I want to add some metadata
attr(df, "query_timestamp") <- lubridate::now()
attr(df$amount, "currency") <- "BRL"
#encoding table for user type
encode <- data.frame("type" = c(1,2),
"description" = c("vendor", "shopper"))
print(attr(df, "query_timestamp"))
[1] "2018-07-18 15:30:57 -03"
print(attr(df$amount, "currency"))
[1] "BRL"
df <- df %>% dplyr::left_join(encode, by = "type")
print(attr(df, "query_timestamp"))
NULL
print(attr(df$amount, "currency"))
[1] "BRL"
Is there any reason for that? I would like to keep attributes but avoid using aux variables to store them.