I got this message error "Error: n() must only be used inside dplyr verbs" from my code. i've already check answers of this bug on internet, but I can't apply any answers to my situation.
Here is the initial code
#create a fubction to get df with only absorption values, in wide, each column for each wl value
library(tidyverse)
transform_wide <- function(data, value, name){
df <- data %>% group_by(lambda) %>%
mutate(row = row_number()) %>%
pivot_wider(names_from = lambda, values_from = {{value}}) %>%
select(-row, - campagne, - depth)
colnames(df) <- gsub(' ', '',paste(name, colnames(df), sep = ''))
return(df)
}
#apply it on each type of abs
real_df <- transform_wide(real_df, real, 'real')
and the dataset looks like this
real_df <- tibble('campagne'= rep('test', 10),
'depth'= c(1:10),
'lambda' = c(rep(440,5), rep(470, 5)),
'real' = runif(10))
It worked few months ago, so I think it might be due to some dplyr version.
Thanks for your help.