Use this function to create a template script that puts package functions in order and, based on question answers, prepopulates some arguments. By default, this function is run in interactive mode, meaning that it will not work in a script unless a list of answers is given to answer_list argument. Note that the saved template file is not intended to be run as is, but only to provide a starting structure for a cleaning script.

make_dua_template(file_name, include_notes = TRUE, answer_list = NULL)

Arguments

file_name

Name with path of template script.

include_notes

If TRUE, the template file will include notes and suggestions for completing the script; default value is TRUE.

answer_list

List of answer strings to provide if you don't want to answer questions interactively. See details for questions and expected input type. Leave as default NULL for interactive mode.

Details

Questions to answer if using the answer_list argument:

  1. Do you want to set the DUA crosswalk file? 'Yes' or 'No'

    1. DUA crosswalk file (with path): '< file name with path >'

  2. Do the data need to be deidentified? 'Yes' or 'No'

    1. Would like to select the ID column now? 'Yes' or 'No'

    2. ID column name: '< column name string >'

If answers to questions (1) and (2) are No, then strings for 1(a), 2(a), and 2(b) can be left empty since they will be ignored.

Examples

if (FALSE) { ## run interactively make_dua_template('data_clean.R') ## ...and don't include extra notes make_dua_template('data_clean.R', include_notes = FALSE) } ## make template to be filled in file <- file.path(tempdir(), 'data_clean.R') make_dua_template(file, answer_list = list('No','','No','','')) ## show writeLines(readLines(file))
#> ################################################################################ #> ## #> ## [ Proj ] < general project name > #> ## [ File ] data_clean.R #> ## [ Auth ] < author name > #> ## [ Init ] 13 June 2021 #> ## #> ################################################################################ #> #> ## --------------------------- #> ## libraries #> ## --------------------------- #> #> ## NOTES: Include additional libraries using either -library()- or -require()- #> ## functions here. #> #> ## --------------------------- #> ## set DUA crosswalk #> ## --------------------------- #> #> ## NOTES: Choose the DUA agreement crosswalk file if you didn't when setting up #> ## the template. If the file is a delimited file that isn't a CSV or TSV, be #> ## sure to indicate the delimiter string with the -delimiter- argument. #> ## Similarly if the crosswalk is in an Excel file on any sheet beyond the #> ## first, set the -sheet- argument to the correct sheet. #> #> set_dua(dua = '< dua crosswalk file name >') #> #> ## --------------------------- #> ## set DUA level #> ## --------------------------- #> #> ## NOTES: Choose the DUA agreement crosswalk level. If you indicated that the #> ## data should be deidentified, those options, including the ID column if #> ## choosen, are included below. If you did not indicate the name of the ID #> ## column to be deidentified, add its name after the -id_column- argument. #> ## #> ## If you did not indicate that the data should be deidentified, but they #> ## should be, see ?deid_dua(). #> #> set_dua_level(level = '< level name >') #> #> ## --------------------------- #> ## data cleaning #> ## --------------------------- #> #> ## NOTES: Use standard scripts to build and clean data set here. #> #> ## --------------------------- #> ## check DUA restrictions #> ## --------------------------- #> #> ## NOTES: If your data frame includes restricted data elements or should have #> ## been deidentified and has not been, -check_dua_restrictions()- will return #> ## an error and stop. Fix above and rerun or set -remove_protected- arguement #> ## to TRUE to automatically remove restricted columns. #> #> check_dua_restrictions(df = '< data frame >') #> #> ## --------------------------- #> ## write cleaned file #> ## --------------------------- #> #> ## NOTES: Write cleaned file to disk. Select the file type (e.g., CSV, TSV, #> ## Stata, Rdata) and include additional arguments required by -haven- or base R #> ## writing functions. #> #> write_dua_df(df = '< data frame >', output_type = '< output file type >' #> #> ## ----------------------------------------------------------------------------- #> ## end script #> ################################################################################