'Function where user supplies a column name and a tbl
I had a function that previously worked where I iterated the same operations over a user input of column names that no longer works. Here's a very simplified scenario in which a user should be able to input a data.frame and a columname and the function should return an operation done on that particular column. This was working about 1 month ago.
df = data.frame(X1 = c(1:10), Y1=letters[1:10])
df
df %>%
mutate(X2=X1 * 2)
tb.test = function(tbl, column) {
tbl2 = tbl %>%
mutate(X2 = {{column}} * 2)
return(tbl2)
}
tb.test(df, X1)
This no longer seems to be working with an error column X1 not found.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
