Hi all, I'm trying to find a way to import multiple files at once into R and I've found this nice little script that works well. Only, there's an odd problem: it works perfectly when I run it in a normal script file, but when I put it into an R Markdown code chunk, it doesn't return anything. Not sure why; any help would be appreciated
Code is here:
file_path <- "JLWOP/Data and Models/"
# view all files
file_path %>% list.files()
# save only file names with the desired extension
csv_file_names=file_path %>%
list.files() %>%
.[str_detect(., ".csv")]
# Load everything into the Global Environment
csv_file_names %>%
purrr::map(function(file_name){ # iterate through each file name
assign(x = str_remove(file_name, ".csv"), # Remove file extension ".csv"
value = read_csv(paste0(file_path, file_name)),
envir = .GlobalEnv)
})
When I run this in an R script, both of my .csv files load in perfectly. When I run it in an R Markdown, all I see is the return
list()
In the Markdown document