This function will truncate the strings in variables according to the length specified
truncate_var_strings(dt, var_name, trunc_length)
dataset with truncated variable
Reporting-related utility functions
convert_var_to_ascii()
,
create_R_script()
# Testing: no truncation
AE <- data.frame(
USUBJID = 1:5,
DOMAIN = "AE",
AESEQ = 1:5,
AESTDTC = 1:5,
AETERM = 1:5,
AEDECOD = 1:5,
stringsAsFactors = FALSE
)
truncate_var_strings(AE, var_name = "AETERM", trunc_length = 50)
#> USUBJID DOMAIN AESEQ AESTDTC AETERM AEDECOD
#> 1 1 AE 1 1 1 1
#> 2 2 AE 2 2 2 2
#> 3 3 AE 3 3 3 3
#> 4 4 AE 4 4 4 4
#> 5 5 AE 5 5 5 5
# Testing: Truncation
AE$AETERM[4] <- "THIS IS A SUPER LONG AE TERM, SO LONG IN FACT THAT ITS OVER 50 CHARACTERS."
AE$AETERM[5] <- "THIS AE TERM IS WAY TOO LONG FOR A NICELY FORMATTED REPORT"
truncate_var_strings(AE, var_name = "AETERM", trunc_length = 50)
#> USUBJID DOMAIN AESEQ AESTDTC AETERM
#> 1 1 AE 1 1 1
#> 2 2 AE 2 2 2
#> 3 3 AE 3 3 3
#> 4 4 AE 4 4 THIS IS A SUPER LONG AE TERM, SO LONG IN FACT...
#> 5 5 AE 5 5 THIS AE TERM IS WAY TOO LONG FOR A NICELY...
#> AEDECOD
#> 1 1
#> 2 2
#> 3 3
#> 4 4
#> 5 5