I am looping a number of csv files in a folder using the map function. I want to save the results of the loop using a sliced version of the name of the csv. But I am getting an error when attempting to save the results to csv. Here is my code
library(tidyverse)
library(fs)
library(dismo)
file_paths <- fs::dir_ls("loop/")
file_paths %>%
map(function (path){
all_data <- read_csv(path, show_col_types = FALSE)
name <- tools::file_path_sans_ext(basename(file_paths))
print(name)
t_max <- all_data[,c(2)]
t_min <- all_data[, c(3)]
rain_fall <- all_data[,c(4)]
res <- data.frame(biovars(t_max, t_min, rain_fall))
myfile = sprintf("%s_bio.csv", name)
write_csv(res, file=myfile, col_names = TRUE)
})
Error:
Error in if (is_url(path)) { : the condition has length > 1
tools::file_path_sans_ext(basename(file_paths))withtools::file_path_sans_ext(basename(path)).