Home > Mobile >  "'what' must be a function or character string" Error during loading data in R
"'what' must be a function or character string" Error during loading data in R

Time:09-01

I am trying to load in some data - a list of CSV files. The code below has worked for other data sets of mine, but not for this one.

setwd("~/Dropbox/prime/word/data")
file.age <- setwd("~/Dropbox/prime/word/data")
age_names <- dir(file.age)
one <- do.call(bind_rows,lapply(age_names,read.csv))

I get the following:

Error: ! Can't combine ..1$Reaction.Time and ..2$Reaction.Time . Backtrace:

  1. base::do.call(bind_rows, lapply(age_names, read.csv))
  2. dplyr (local) <fn>(...)
  3. vctrs::vec_rbind(!!!dots, .names_to = .id)

Having a look through some of the data... in the "reaction time" column there is sometimes a "LOADING DELAY" value rather than a numerical value... might this be the issue?

If it is, is there a way to filter that out on the way in? I've tried appending "%>% filter(reaction_time != "LOADING DELAY")" to the code, but I get the same issue.

Thanks a lot in advance!

CodePudding user response:

We could specify the column type of the specific column as character while reading and then it should work

library(dplyr)
library(readr)
library(purrr)
map_dfr(age_names, ~ read_csv(.x, col_types = cols(Reaction.Time = "c")))
  • Related