I have a df that is will be of nonfinite length. Example below only has 2 traits: "density" and "lipids", but other dfs may have 50 or more traits. Each trait has 3 columns associated with it: value.trait, unit.trait, method.trait. Seems very similiar to this example in vignette But when I run the code below I keep getting an error: Input must be a vector, not NULL
3 rows of sample data
x <- structure(list(geno_name = c("MB mixed", "MB mixed", "MB mixed"
), study_location = c("lab", "lab", "lab"), author = c("test",
"test", "test"), value.lipids = c(NA, 2.361463603, 1.461189384
), unit.lipids = c(NA, "g cm^-2", "g cm^-2"), method.lipids = c(NA,
"airbrush", "airbrush"), value.density = c(1.125257337, 0.816034359,
0.49559013), unit.density = c("g cm^-3", "g cm^-3", "g cm^-3"
), method.density = c("3D scanning", "3D scanning", "3D scanning"
)), row.names = c(NA, 3L), class = "data.frame")
Current pivot code:
x %>%
select(!c(study_location, author)) %>%
pivot_longer(cols = !geno_name,
names_to = c(".value", "trait"),
names_sep = ".",
values_drop_na = TRUE)
Error code:
Error: Input must be a vector, not NULL. Run
rlang::last_error()
to see where the error occurred. In addition: Warning messages: 1: In gsub(paste0("^", names_prefix), "", names(cols)) : argument 'pattern' has length > 1 and only the first element will be used 2: Expected 2 pieces. Additional pieces discarded in 6 rows [1, 2, 3, 4, 5, 6].