read_list: Read a lot of datasets at once with R

View source: R/read_list.R

read_listR Documentation

Read a lot of datasets at once with R

Description

Supply a list of data sets and the function to read the datasets. For example, to read in .csv files, use readr::read_csv. This function comes from Bruno Rodrigues' website and credit goes to him.

If you prefer not to have the datasets in a list, but rather import them into the global environment, then use read_list2.

Usage

read_list(list_of_datasets, read_func)

read_list2(list_of_datasets, read_func, envir = .GlobalEnv)

Arguments

list_of_datasets

A character vector with names of data sets to read.

read_func

Function to read the data sets.

envir

Environment to assign data frames to. Default is .GlobalEnv. Used in read_list2 only.

Value

A list of data sets

References

http://www.brodrigues.co/blog/2016-07-26-read-a-lot-of-datasets-at-once-with-r/

Examples

## Not run: 
library(dplyr)
library(stringr)
library(readr)

csv_path <- "C:/Users/latour/Dropbox/repos/lamisc/inst/extdata"

(data_files <- list.files(path = csv_path,
                          pattern = ".csv"))

setwd(csv_path)

#### read_list --------------------------------
list_of_data_sets <- read_list(list_of_datasets = data_files,
                               read_func = readr::read_csv)

dplyr::glimpse(list_of_data_sets)


#### read_list2 --------------------------------
read_list2(list_of_datasets = data_files,
           read_func = readr::read_csv)

## End(Not run)

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.