Skip to content

Instantly share code, notes, and snippets.

@mattpolicastro
Created March 17, 2016 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpolicastro/fd1088ceb6a2aeef5dcc to your computer and use it in GitHub Desktop.
Save mattpolicastro/fd1088ceb6a2aeef5dcc to your computer and use it in GitHub Desktop.
A quick-and-dirty .rpt-to-.csv file converter. No safety for escapes. ¯\_(ツ)_/¯
text <- readLines("file.rpt")
col_lengths <- unlist(lapply(strsplit(text[2], " "), nchar))
new_cols <- list()
for(col in 1:length(col_lengths)) {
current_len <- col_lengths[col]
new_cols[[col]] <- as.character(gsub("^\\s+|\\s+$", "", strtrim(text, current_len)))
text <- substring(text, current_len + 2)
}
remove(col)
data <- as.data.frame(new_cols, stringsAsFactors = FALSE)
names(data) <- unlist(data[1,])
data <- data[3:nrow(data),]
write.csv(data, file = "file.rpt.csv", row.names = F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment