-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
52 lines (34 loc) · 1.51 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
---
output: github_document
---
<!-- badges: start -->
<!-- badges: end -->
<img src="https://media.giphy.com/media/6ZnDM7tOjKTRe/giphy-downsized.gif" align="right" />
<center><h1>✨ fwiffer ✨</h1></center>
Getting column positions and widths for parsing fixed width file formats is painful. Tape measures are dangerous and useless for measuring column widths. If your data is stored in fixed width files but `readr::read_fwf()` can't guess the column widths, then you need a new tool.
## Installation
You can install the released version of fwiffer from GitHub
``` r
# install.packages("devtools")
devtools::install_github("gadenbuie/fwiffer")
```
## Fixed Width Files Made Easy 😅
Open your fixed-width data file and use <kbd>Command</kbd> + <kbd>Alt</kbd> + click to add cursors at the start of each column. They don't have to be on the same line or in the same order!

Then choose the RStudio addin of your choice:
* **Cursors to Column Widths**
* **Cursors to Column Start/End**
And get back the `readr::read_fwf()` code you need. Edit the names in `col_names` and move on with your day!
### Column Widths
```{r}
col_widths <- c(20, 10, 11)
col_names <- c("X01", "X02", "X03")
readr::read_fwf("inst/fwf-sample.txt", readr::fwf_widths(col_widths, col_names))
```
### Column Start/End
```{r}
col_starts <- c(1, 21, 31)
col_ends <- c(20, 30, 42)
col_names <- c("X01", "X02", "X03")
readr::read_fwf("inst/fwf-sample.txt", readr::fwf_positions(col_starts, col_ends, col_names))
```