0

Having trouble with my code while trying to import my data with a column that exceeds the maximum integer (.Machine$integer.max = 2147483647). Using readr's read_csv I believe it's importing as NA instead of rounding off. The complication comes from trying to import multiple csvs with rbindlist.

Here is my current setup:

 load_df_path <- file.path(".../dffolder") #path to folder
 df_path_files <- list.files <- (load_df_path, full.names = TRUE) #list files in path

 df <- rbindlist(lapply(df_path_files, read_csv)) # read in csvs using readr

How do I write the last line to import the csvs and turn the column "amount" to characters instead of integers?

Here are a few things I tried without any luck...

## This gets error: Error in switch(tools::file_ext(path)....
 df <- rbindlist(lapply(df_path_files, read_csv(df_path_files, col_types = list(amount = col_character())))) 


## recreate read_csv and changed col_types = NULL to the above but getting the warning
## Error in FUN(X[[i]], ...) : could not find function "read_delimited"

tl;dr - need help importing a list of csvs while changing specific column to character format or an int64.

Thank you.

ant
  • 565
  • 1
  • 6
  • 12

1 Answers1

1

You are almost there, just the syntax...

df_list <- lapply(df_path_files, read_csv, col_types = cols(amount = col_character()))
df <- rbindlist(df_list)

col_types expects NULL or something created by cols. See ?read_csv and ?cols.

One other idea: Maybe enforcing numeric instead of int could be a solution: Using cols(amount = col_double()) See here: long/bigint/decimal equivalent datatype in R

Community
  • 1
  • 1
Rentrop
  • 20,979
  • 10
  • 72
  • 100