map_df permission denied from files on desktop

So I made a new project for a case study. Put it in my projects folder on my desktop. Put a data folder in there containing 40 .csv files. Now what I'm trying to do is set the directory and aggregate all the data using map_df.

However I'm running into an issue where my permission is being denied?
Here is my code:


bs_csv_file_dir <- "C:/Users/fakename/Desktop/Projects/BikeShare_MemberAnalysis/Cyclistic Data/202004-202307_Cyclistic"

bs_csv_files <- list.files(path = bs_csv_file_dir, pattern = ".csv")

bs_csv_data <- map_df(bs_csv_files, ~read_csv(file.path(bs_csv_file_dir)))

and the error message is:

Error in `map()`:
ℹ In index: 1.
Caused by error in `file()`:
! cannot open the connection
Run `rlang::last_trace()` to see where the error occurred.
Warning message:
In file(con, "rb") :
  cannot open file 'C:/Users/fakename/Desktop/Projects/BikeShare_MemberAnalysis/Cyclistic Data/202004-202307_Cyclistic': Permission denied

The following should work:

bs_csv_files <- list.files(
  path = bs_csv_file_dir,
  full.names = TRUE, # to list full file paths, not just file names
  pattern = "\\.csv$" # to ensure you actually target .csv files

bs_csv_data <- map_df(bs_csv_files, read_csv)

You can cut a step:

bs_csv_data <- read_csv(bs_csv_files)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.