Description Usage Arguments Details Examples
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.
1 2 3 4 5 6 | 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()
csv: write.table(...,row.names = FALSE, sep = ,)
tsv: write.table(...,row.names = FALSE, sep = '\t')
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## --------------
## 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')
## Not run:
write_dua_df(df, 'clean_data', output_type = 'delimited', sep = '|')
write_dua_df(df, 'clean_data', output_type = 'stata', version = 11)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.