How to read in hundreds of CSV files with one line of code
Ever found yourself staring at a folder full of CSV files, wondering how on earth you're going to import them all without writing a ton of code? I've been there! I used to think I needed some complex solution, but it turns out you can do it with just one line of code.
In this quick video, I show you how to:
Use the {fs} package along with the tidyverse
Create a vector of all your CSV files in a directory
Import them all at once using read_csv() (not read.csv()!)
The best part? This method automatically combines all your CSV files into a single tibble. In my example, it took hundreds of CSV files and turned them into one neat dataset with 100,000 rows. Pretty cool, right?
Here's the code that I used:
library(tidyverse)
library(fs)
csv_files <-
dir_ls(
path = "csv_files"
)
read_csv(csv_files)
Sign up for the newsletter
Get blog posts like this delivered straight to your inbox.
You need to be signed-in to comment on this post. Login.