Converts line endings of text files from CRLF (\r\n) to LF (\n) or the
reverse.
convert_line_endings( files, direction = c("to_lf", "to_crlf"), root = NULL, force = FALSE, silent = TRUE )
| files | Character vector of file paths; these may be relative to |
|---|---|
| direction | Whether conversion is to LF ( |
| root | An optional directory path; if present the |
| force | Logical; |
| silent | Logical. Whether to print the return value to the console. |
The files argument; invisibly unless silent = FALSE.
The conversion to LF is especially helpful to maintain file integrity across
platforms in combination with a distributed version control system like
git.
To prevent unneeded rewriting, the "to_lf" direction is only executed in
Windows systems, unless force = TRUE.
The function is designed so that it can take the output of
git2rdata::write_vc() as input in a pipeline; still the root argument may
need to be repeated in such case.
The function borrows from TAF::dos2unix() and TAF::unix2dos(),
which work on single files.
To prevent git from automatically replacing line endings in specific files
when checking out new versions of those files, set LF as the required line
ending of specific file types in a .gitattributes file in the root of the
git repository, and commit this file so that collaborators use the same
setting. An example line in .gitattributes looks like this (this example
makes line endings of yml files always use LF):
*.yml text eol=lf
Note that, with this setting, to have existing files updated by git they
first need to be removed from the working directory, after which you can do a
checkout again for these files.
Other functions regarding file management for N2KHAB projects:
checksum(),
download_zenodo(),
fileman_folders(),
fileman_up(),
get_zenodo_versions(),
locate_n2khab_data()
if (FALSE) { files <- c(file1, file2) convert_line_endings(files) }