View source: R/strip_attributes.R
strip_attributes | R Documentation |
strip additional attributes that make dplyr fail
strip_attributes(df, attr_names)
df |
dataframe |
attr_names |
names of attributes that you want to remove |
dplyr as of 0.4 still does not handle columns with non-generic attributes and will error out rather than ignoring them etc. This function will allow one to strip attribute names to allow the data frame to be used within the dplyr pipeline without issue.
This type of data is common when dealing with SAS datasets
foo <- data.frame(a = 1:5, b = 1:5, c=letters[1:5]) df <- foo attr(df$a, "label") <- "col a" attr(df$b, "label") <- "col b" attr(df$c, "label") <- "col c" library(dplyr) df %>% filter(a %in% c(1, 2)) # used to throw an error in old versions df %>% strip_attributes("label") %>% filter(a %in% c(1, 2)) attr(df$a, "notes") <- "a note" # now column a has attributes of label and notes df %>% strip_attributes(c("label", "notes")) %>% filter(a %in% c(1, 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.