Package 'fpeek'

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-08-25 04:25:10 UTC
Source: https://github.com/davidgohel/fpeek

Help Index


number of lines of a file

Description

return the number of lines found in a file. Operation is counting the number of new line symbols in the file.

Usage

peek_count_lines(path, with_eof = FALSE)

Arguments

path

file path

with_eof

count the end of file as a new line.

Value

number of lines as an integer

Examples

f <- system.file(package = "fpeek",
  "datafiles", "cigfou-ISO-8859-1.txt")
peek_count_lines(f)

print the first lines of files

Description

print the first n lines of a file.

Usage

peek_head(path, n = 10, intern = FALSE)

Arguments

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.

Examples

f <- system.file(package = "fpeek",
  "datafiles", "cigfou-ISO-8859-1.txt")
peek_head(f, n = 4)
peek_head(f, n = 4, intern = TRUE)

Converts encoding of characters

Description

Read a file, convert the encoding of characters and print the result.

Usage

peek_iconv(path, from, to = "UTF-8", newfile = NULL)

Arguments

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.

Examples

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 lines of files

Description

print the last n lines of a file.

Usage

peek_tail(path, n = 10, intern = FALSE)

Arguments

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.

Examples

f <- system.file(package = "fpeek",
  "datafiles", "cigfou-ISO-8859-1.txt")
peek_tail(f, n = 4)
peek_tail(f, n = 4, intern = TRUE)