txt2csv {chinese.misc}R Documentation

Write Many Separated Files into a CSV

Description

Given filenames, folder names, or the mixture of the two, the function will read texts in .txt or other separated files, and then write them into one .csv file. It helps those who prefer texts in a table format.

Usage

txt2csv(..., csv, must_txt = TRUE, na_in_txt = NULL)

Arguments

...

names of folders and files, obtained files may end with ".txt" or not , see below. Encoding for each file is auto-detected.

csv

a .csv file that will contain texts. It must end with ".csv".

must_txt

should be TRUE or FALSE. Should all qualified texts end with ".txt"? If you want to read other types of file, such as .rtf, set it to FALSE. Default is TRUE.

na_in_txt

character vector that specifies what content, when it occupies a single line, should be treated as NA. See Details. Length of it can be larger than 1.

Details

Whether a file is taken as NA is judged by scancn. " " (a space) is also taken as NA. However, you can further decide what else is deemed as NA, e. g., "404 ERROR", if your texts are from websites. If a file cannot be accessed, the result to be written in the corresponding cell of csv file will become NA, and there will be a message, but no error is raised. In the .csv file, full filenames of txt occupy a column and fulltexts occupy another.

Examples

## Not run: 
x1 <- file.path(find.package("base"), "CITATION")
x2 <- file.path(find.package("base"), "DESCRIPTION")
txt2csv(x1, x2, must_txt = FALSE, csv = 'x1x2csv.csv')

## End(Not run)

[Package chinese.misc version 0.2.3 Index]