This function is a wrapper for a variety of write functions that also checks whether the data set has been cleared for writing based on the DUA level restrictions chosen by the user. If restricted variables remain in the data set, the function will return an error and will not write the data set.
write_dua_df( df, file_name, output_type = c("rds", "rdata", "csv", "tsv", "delimited", "stata", "sas", "spss"), ... )
df | Data frame object to save. |
---|---|
file_name | Name and path for saved file, with or without file type ending. |
output_type | Output data file type; options include
|
... | Arguments to pass to write function based on the
selected |
The following output types are supported (with the underlying write function and default arguments accompanying):
rds: saveRDS()
rdata: save()
delimited: write.table(...,row.names = FALSE)
stata: haven::write_dta()
sas: haven::write_sas()
spss: haven::write_sav()
All arguments for these internal write functions, including those
with default values, can be modified by adding them to the
top-level write_dua_df()
function.
## -------------- ## Setup ## -------------- ## set DUA crosswalk dua_cw <- system.file('extdata', 'dua_cw.csv', package = 'duawranglr') set_dua_cw(dua_cw)#>#>## read in data admin <- system.file('extdata', 'admin_data.csv', package = 'duawranglr') df <- read_dua_file(admin) ## set restriction level set_dua_level('level_iii') ## remove restrictive variables df <- dplyr::select(df, -c(sid,sname,tname)) ## -------------- ## check restrictions check_dua_restrictions(df)#>#>## able to write since restrictions check passed file <- file.path(tempdir(), 'clean_data.csv') write_dua_df(df, file_name = file, output_type = 'csv') if (FALSE) { write_dua_df(df, 'clean_data', output_type = 'delimited', sep = '|') write_dua_df(df, 'clean_data', output_type = 'stata', version = 11) }