Fehler: не может подмножество столбцов, которые не существуют. x Столбец plot_id не существует - PullRequest
0 голосов
/ 24 марта 2020

Привет, ребята. У меня проблемы с RStudio. Следующие области моих заказов:

library(tidyverse)
library(asdreader)

read_spectra <- function(dir_to_data = "I:/Master Arbeit/ASD Data to work/Data_Dok/20200315_DOK",
                     meas_protocol = "I:/Master Arbeit/ASD Data to work/Data_Dok/2020_03_15_DOK_table.csv",
                     n_meas = 10, format = "asd"){

  fnames <- list.files(dir_to_data, pattern = paste0(".", format), full.names = T)

  meas_id <- str_sub(fnames, -9, -1) %>% strsplit(., ".", fixed = T) %>% 
lapply(., "[[", 1) %>% unlist() %>% as.numeric()

  if(format == "sed"){
files <- as.list(fnames)
spc <- lapply(files, read_delim, delim = "\t", skip = 26) %>% 
  lapply(., spread, Wvl, `Reflect. %`) %>% do.call("rbind", . )
#transform from % reflectance to %/100 reflectance
spc <- as_tibble(spc/100)
  } else if (format == "asd"){
spc <- asdreader::get_spectra(fnames, type = "reflectance") %>% 
  as_tibble()
  } else {
print("format must be either sed or asd")
  }

  #rename columns
  colnames(spc) <- unique(paste("rflt", names(spc), sep = "_"))

  spc$meas_id <- meas_id

  design <- read_csv(meas_protocol) %>% as_tibble() %>% 
    dplyr::select(plot_id, meas_nr) %>% 
    filter(complete.cases(.))

  meas_seq <- as.numeric(design$meas_nr)

  #For robustness against errors in meas_seq  
  idx <- lapply(meas_seq, FUN = function(x) seq(x, length.out = n_meas)) %>% 
    unlist()

  design2 <- design[rep(seq_len(nrow(design)), each = n_meas), ]

  full <- cbind(design2, idx)

  #Check  
  sub <- seq(from = 1, to = nrow(full), by = n_meas)
  identical(full[sub,]$meas_nr, full[sub,]$idx)

  full <- full %>% dplyr::select(-meas_nr)

  spc_out <- left_join(full, spc, by = c("idx" = "meas_id")) %>% 
    as_tibble()

}

#Test run

asd <- read_spectra(dir_to_data = "I:/Master Arbeit/ASD Data to work/Data_Dok/20200315_DOK",
                meas_protocol = "I:/Master Arbeit/ASD Data to work/Data_Dok/2020_03_15_DOK_table.csv",
                n_meas = 10,
                format = "asd")

Когда я пытаюсь запустить тестовый запуск ASD, я получаю следующее сообщение об ошибке и трассировку:

Parsed with column specification:
cols(
  `plot_id;meas_nr` = col_character()
)
 Fehler: Can't subset columns that don't exist.
x The column `plot_id` doesn't exist.
Run `rlang::last_error()` to see where the error occurred. 
20.
stop(fallback) 
19.
rlang:::signal_abort(x) 
18.
cnd_signal(cnd) 
17.
value[[3L]](cond) 
16.
tryCatchOne(expr, names, parentenv, handlers[[1L]]) 
15.
tryCatchList(expr, classes, parentenv, handlers) 
14.
tryCatch(instrument_base_errors(expr), vctrs_error_subscript = function(cnd) {
    cnd$subscript_action <- subscript_action(type)
    cnd$subscript_elt <- "column"
    cnd_signal(cnd) ... 
13.
with_subscript_errors(vars_select_eval(vars, expr, strict, data = x, 
    name_spec = name_spec, uniquely_named = uniquely_named, type = type), 
    type = type) 
12.
eval_select_impl(NULL, .vars, expr(c(!!!dots)), include = .include, 
exclude = .exclude, strict = .strict, name_spec = unique_name_spec, 
uniquely_named = TRUE) 
11.
tidyselect::vars_select(tbl_vars(.data), !!!enquos(...)) 
10.
select.data.frame(., plot_id, meas_nr) 
9.
dplyr::select(., plot_id, meas_nr) 
8.
function_list[[i]](value) 
7.
freduce(value, `_function_list`) 
6.
`_fseq`(`_lhs`) 
5.
eval(quote(`_fseq`(`_lhs`)), env, env) 
4.
eval(quote(`_fseq`(`_lhs`)), env, env) 
3.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
2.
read_csv(meas_protocol) %>% as_tibble() %>% dplyr::select(plot_id, 
    meas_nr) %>% filter(complete.cases(.)) 
1.
read_spectra(dir_to_data = "I:/Master Arbeit/ASD Data to work/Data_Dok/20200315_DOK", 
    meas_protocol = "I:/Master Arbeit/ASD Data to work/Data_Dok/2020_03_15_DOK_table.csv", 
    n_meas = 10, format = "asd") 

Я использую RStudio версию RStudio версии 1.2.5033, и мои данные выглядят следующим образом: Изображение моей таблицы данных

Я не понимаю, почему Rstudio не распознает column plot_id

Спасибо за вашу помощь.

...