generate_sas_readfile: Generates .csv and .sas files from a data.table

View source: R/generate_sas_readfile.R

generate_sas_readfileR Documentation

Generates .csv and .sas files from a data.table

Description

Generates .csv and .sas files from a data.table

Usage

generate_sas_readfile(
  data,
  filename_stub,
  shortener = function(x) {
     substr(x, 1, 30)
 }
)

sasify(
  data,
  filename_stub,
  shortener = function(x) {
     substr(x, 1, 30)
 }
)

shorten_no_vowels(x)

Arguments

data

A data.table object

filename_stub

A character string which will be the filename of the generated files, eg, filename_stub.csv and filename_stub.sas.

shortener

A function which shortens variable names if longer than 30 characters

Details

The function generates 3 files:

  • filename_stub.csv

  • filename_stub.sas

  • filename_stub-variable-listing.csv

The variable listing provides details on variable names, type, length, and the original variable name (unabridged_name) if

  • the variable name was changed to comply with variable name character count restrictions, or

  • non alpha-numeric characters were removed from the variable name.

shorten_no_vowels is a custom shortener which removes vowels prior to selecting the first 30 characters

Examples

iris_dt <- as.data.table(iris)
generate_sas_readfile(iris_dt, "iris")

# Long variable names
# Default shortener simply cuts the variable name at 30 characters
iris_dt$very_long_variable_name_that_exceeds_character_count_restrictions <- 1
generate_sas_readfile(iris_dt, "iris2")

# Custom shortener
shorten <- function(x){
  y <- gsub("a|e|i|o|u","",x)
  substr(y,1,30)
}
generate_sas_readfile(iris_dt, "iris3", shortener = shorten)

thomasgstewart/tgsify documentation built on Oct. 26, 2024, 8:15 p.m.