write_dua_df {duawranglr}R Documentation

Write DUA approved data set

Description

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.

Usage

write_dua_df(
  df,
  file_name,
  output_type = c("rds", "rdata", "csv", "tsv", "delimited", "stata", "sas", "spss"),
  ...
)

Arguments

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 rds (DEFAULT), rdata, csv, tsv, delimited, stata, sas, and spss.

...

Arguments to pass to write function based on the selected output_type; see details for more information.

Details

The following output types are supported (with the underlying write function and default arguments accompanying):

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.

Examples

## --------------
## 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)


[Package duawranglr version 0.6.7 Index]