Read text file with readLines and answer a df
readlines_in_df.Rd
This function reads the content of a text file line by line and stores it in a data frame. You must pick up the FIRST col' for the file_path readed, and the LAST col for the content readed intermediar are additionnal info, i.e. line_number
Usage
readlines_in_df(
files_path,
return_lowered_text = FALSE,
.verbose = TRUE,
file_path_col_name = "file_path",
content_col_name = "content",
line_number_col_name = "line_number",
trimws_line = FALSE
)
Arguments
- files_path
character
Path(s) or url(s) to the text files to read.- return_lowered_text
logical
, default =FALSE
TRUE for lowercasing the returned text. FALSE (the default) will preserve the readed text- .verbose
logical
, default =TRUE
IfTRUE
, shows a progress bar while reading the file.- file_path_col_name
character
, default ="file_path"
Column name for the file path in the output dataframe.- content_col_name
character
, default ="content"
Column name for the file content in the output dataframe.- line_number_col_name
character
, default ="line_number"
Column name for the line numbers in the output dataframe.- trimws_line
logical
, default =FALSE
. trim white space(s) at the end and the begining of each line
Value
Return a data.frame
with 3 columns.
The last column (content
by default) contain the readed lines from the file.
- file_path
character
Path of the file where the match was found.- line_number
integer
Line number in the file.- content
character
Content of the line.
Examples
if (FALSE) { # \dontrun{
df <- readlines_in_df("path/to/file.R", case.sensitive = TRUE)
contents_readed <- df[[ncol(df)]]
file_path_readed <- df[[1]]
} # }