This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Generate fixed width file in R | |
#' @description This simple function creates fixed width file with no | |
#' extra dependencies. | |
#' @param justify "l", "r" or something like "lrl" for left, right, left. | |
#' @examples dt <- data.frame(a = 1:3, b = NA, c = c('a', 'b', 'c')) | |
#' write_fwf(dt, "test.txt", width = c(4, 4, 3)) | |
#' @export | |
write_fwf = function(dt, file, width, | |
justify = "l", replace_na = "NA") { | |
fct_col = which(sapply(dt, is.factor)) |