Skip to content

Instantly share code, notes, and snippets.

@eleakin
eleakin / text2csv.R
Created November 23, 2017 17:27 — forked from benmarwick/test.R
Convert a folder of text files into a single CSV file with one column for the file names and one column of the text of the file. A function in R.
#' Compiling several text files into a single CSV file
#'
#' Convert a folder of text files into a single CSV file
#' with one column for the file names and one column of the
#' text of the file. A function in R.
#'
#' To use this function for the first time run this next line:
#' install.packages("devtools")
#' then thereafter you just need to load the function
#' fom github like so, with these two lines:
@benmarwick
benmarwick / test.R
Last active March 23, 2022 02:29
Convert a folder of text files into a single CSV file with one column for the file names and one column of the text of the file. A function in R.
# test it by creating some small text files to run the function on
txt <- c("here is", "some text", "to test", "this function with", "'including a leading quote", '"and another leading quote')
# make text files
dir.create("testdir")
for(i in 1:length(txt)){
writeLines(txt[i], paste0("testdir/outfile-", i, ".txt"))
}
# run the function and then look in the CSV file that is produced.