-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
111 lines (77 loc) · 2.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(flextable)
```
<!-- badges: start -->
[![R build status](https://github.com/davidgohel/fpeek/workflows/R-CMD-check/badge.svg)](https://github.com/davidgohel/fpeek/actions)
<!-- badges: end -->
## fpeek
<a href="https://github.com/davidgohel/fpeek"><img src="man/figures/logo.png" alt="fpeek logo" align="right" /></a>
The goal of fpeek is to help importation of text files from R.
When a text file has unknown characteristics, beeing able
to have a glance at it helps to get those:
* Use function `peek_count_lines()` to count lines contained in a file.
* Functions `peek_head()` and `peek_tail()` will display
first and last lines of the file.
Sometimes encoding is an issue when files generated on a "Windows" machine
has to be used on a "Linux" machine. Function `peek_iconv` will converts
file content in one encoding to another encoding.
Performances are good with large files because operations are made
without reading the entire file before starting.
## Installation
```{r 'github-install', eval=FALSE}
devtools::install_github("davidgohel/fpeek")
```
## Examples
First download an example file, the file is containing lot of times series
about power system and has lot of lines.
```{r 'download-file'}
library(fpeek)
power_file <- "singleindex.csv"
if( !file.exists(power_file))
download.file(
"https://data.open-power-system-data.org/time_series/2018-03-13/time_series_15min_singleindex.csv",
destfile = power_file)
```
### Counting number of lines:
Using `wc -l`
```{r 'wcl-ex'}
system(sprintf("wc -l %s", power_file), intern = TRUE)
```
Using `peek_count_lines()`
```{r 'nlines-ex'}
peek_count_lines(power_file)
```
### Show first and last lines of a file
The first lines can be printed in the console with function `peek_head()`.
```{r 'head-show-ex'}
peek_head(power_file, n = 4)
```
The last lines can be printed in the console with function `peek_tail()`.
```{r 'tail-show-ex'}
peek_tail(power_file, n = 4)
```
### File reencoding
```{r 'file-iconv-ex'}
la_cigale <- system.file(package = "fpeek", "datafiles",
"cigfou-ISO-8859-1.txt")
peek_head(path = la_cigale, n = 4, intern = TRUE)
peek_iconv(la_cigale, from = "ISO-8859-1", to = "UTF-8")
```
Function `peek_iconv()` is converting the content of the file
and print the result in the console. Use `peek_iconv(newfile = "...")` to create
a new reencoded file:
```{r 'file-iconv-sink-ex'}
file_utf8 <- tempfile()
peek_iconv(path = la_cigale, newfile = file_utf8,
from = "ISO-8859-1", to = "UTF-8")
```