Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gadenbuie/fwiffer
📏✨ Fixed width file definitions made easy
https://github.com/gadenbuie/fwiffer
Last synced: 16 days ago
JSON representation
📏✨ Fixed width file definitions made easy
- Host: GitHub
- URL: https://github.com/gadenbuie/fwiffer
- Owner: gadenbuie
- Created: 2019-09-13T14:09:36.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-29T04:02:21.000Z (about 3 years ago)
- Last Synced: 2024-10-14T22:30:11.915Z (about 1 month ago)
- Language: R
- Homepage:
- Size: 60.5 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---
✨ fwiffer ✨
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 Command + Alt + 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!
![](man/figures/fwiffer.png)
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))
```