Bulk import SPSS(sav) and STATA(dta), MS Excel(csv) Rdata and RDS files into R
Source:R/import_bulk.R
import_bulk.Rd
Many NEAR databases stroe data in SPSS or STATA and MS Excel. Therefore chances are that we need to import many different files at a time in R for further analysis. This function is to bulk import data files of types mentioned above into R environment.
Arguments
- data_dir
The folder storing data files.
- file_type
The data file type. Options could be 'sav' or 'dta', 'csv', 'Rdata' or 'rds'. Default is 'all'.
sav uses
read_sav()
from 'haven' package.dta uses
read_dta()
from 'haven' package.csv uses
read.csv()
from 'utils' package.xlsx uses
read_excel()
from 'readxl' package.The default 'all' imports all five kinds of data.
Value
Two results as follows:
Import SPSS files in
data_dir
to R global environment;List names of tables imported to R.
Note
here
function is a fast and neat way of defining data directorydata_dir
.Be careful when importing the csv files. It could be messy since this function just uses default parameters of
read.csv()
.For 'Rdata' files, it can read 'Rdata', 'RData', "rdata".
For 'Rds' files, it can read 'Rds' or 'rds'.