Title: | Check Text Files Content at a Glance |
---|---|
Description: | Tools to help text files importation. It can return the number of lines; print the first and last lines; convert encoding. Operations are made without reading the entire file before starting, resulting in good performances with large files. This package provides an alternative to a simple use of the 'head', 'tail', 'wc' and 'iconv' programs that are not always available on machine where R is installed. |
Authors: | David Gohel [aut, cre] |
Maintainer: | David Gohel <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2 |
Built: | 2024-11-18 04:23:27 UTC |
Source: | https://github.com/davidgohel/fpeek |
return the number of lines found in a file. Operation is counting the number of new line symbols in the file.
peek_count_lines(path, with_eof = FALSE)
peek_count_lines(path, with_eof = FALSE)
path |
file path |
with_eof |
count the end of file as a new line. |
number of lines as an integer
f <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_count_lines(f)
f <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_count_lines(f)
print the first n
lines
of a file.
peek_head(path, n = 10, intern = FALSE)
peek_head(path, n = 10, intern = FALSE)
path |
file path |
n |
number of lines to print |
intern |
a logical which indicates whether to capture the output as an R character vector or to print the output in the R console. |
f <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_head(f, n = 4) peek_head(f, n = 4, intern = TRUE)
f <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_head(f, n = 4) peek_head(f, n = 4, intern = TRUE)
Read a file, convert the encoding of characters and print the result.
peek_iconv(path, from, to = "UTF-8", newfile = NULL)
peek_iconv(path, from, to = "UTF-8", newfile = NULL)
path |
file path |
from |
the code set in which the input is encoded. |
to |
the code set to which the output is to be converted. |
newfile |
result file. Default to NULL. If null the result will be print in the R console, otherwise a file is produced containing the result. |
la_cigale <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_head(la_cigale) peek_iconv(la_cigale, from = "ISO-8859-1", to = "UTF-8") newfile <- tempfile() peek_iconv(la_cigale, from = "ISO-8859-1", to = "UTF-8", newfile = newfile) peek_head(newfile, n = 10)
la_cigale <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_head(la_cigale) peek_iconv(la_cigale, from = "ISO-8859-1", to = "UTF-8") newfile <- tempfile() peek_iconv(la_cigale, from = "ISO-8859-1", to = "UTF-8", newfile = newfile) peek_head(newfile, n = 10)
print the last n
lines
of a file.
peek_tail(path, n = 10, intern = FALSE)
peek_tail(path, n = 10, intern = FALSE)
path |
file path |
n |
number of lines to print |
intern |
a logical which indicates whether to capture the output as an R character vector or to print the output in the R console. |
f <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_tail(f, n = 4) peek_tail(f, n = 4, intern = TRUE)
f <- system.file(package = "fpeek", "datafiles", "cigfou-ISO-8859-1.txt") peek_tail(f, n = 4) peek_tail(f, n = 4, intern = TRUE)