strip_attributes: strip additional attributes that make dplyr fail

Description Usage Arguments Details Examples

View source: R/strip_attributes.R

Description

strip additional attributes that make dplyr fail

Usage

1
strip_attributes(df, attr_names)

Arguments

df

dataframe

attr_names

names of attributes that you want to remove

Details

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
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)) # will throw an error
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))

## End(Not run)

Example output

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

  a b c
1 1 1 a
2 2 2 b
  a b c
1 1 1 a
2 2 2 b
  a b c
1 1 1 a
2 2 2 b

PKPDmisc documentation built on April 14, 2020, 5:49 p.m.