-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
146 lines (105 loc) · 4.74 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
```{r make-sticker, include=FALSE}
if (!file.exists("man/figures/logo.png") &&
!identical(Sys.getenv("USERDOMAIN"), "POPDATA")) {
source("inst/sticker/sticker.R")
}
```
# dipr <img src='man/figures/logo.png' align="right" height="139" />
<!-- badges: start -->
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![R build status](https://github.com/bcgov/dipr/workflows/R-CMD-check/badge.svg)](https://github.com/bcgov/dipr)
[![img](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
<!-- badges: end -->
The `dipr` package is an R package that loads and provides means of caching of `.dat.gz` files. Functions are also provided to convert from `.dat.gz` files to Apache Arrow formats.
## Installation
While this package is intended for us within the SRE you can install the package from GitHub:
```{r, eval=FALSE}
if(!requireNamespace("remotes")) install.packages("remotes")
remotes::install_github("bcgov/dipr")
```
## Installation inside the SRE
Installation of `dipr` is slightly different than typical R package installation. To begin with you will need to clone the dipr repo. To do this you need access to the SRE instance of GitLab.
Go to this website: https://projectsc.popdata.bc.ca/
Scroll down and click on "Sign in with Pop Data Sso"
You will need to do this step everytime you log into the SRE.
Next go to this site: https://projectsc.popdata.bc.ca/profile/personal_access_tokens
Create a new Personal Access Token enabling each scope and typing in your username. This should create a new personal access token. Those are your "git credentials". Save those on your "U" drive along with your user name.
### Install from R
```{r eval=FALSE}
## First you need to store your credentials created in the step above. This is a one time only thing
token <- credentials::git_credential_ask("https://projectsc.popdata.bc.ca")$password
## These next two lines download the package to a temporary folder and install it.
resp <- httr::GET("https://projectsc.popdata.bc.ca/api/v4/projects/90/repository/archive.tar.gz",
query = list(sha = "1.3.1"),
httr::write_disk(tempfile(fileext = ".tar.gz")),
config = httr::add_headers(`Private-token` = token))
remotes::install_local(resp[["content"]])
```
## Usage
The `dipr` package comes with some sample _fake_ data to illustrate the usage of the package and facilitate unit tests. Specifically, the package provides a fake data dictionary and a compressed data file. Example fake data can be seen like this:
```{r}
library(dipr)
dipr_examples()
```
Individual paths can be extracted like this:
```{r}
data_dict_path <- dipr_example("starwars-dict.txt")
dict <- read.table(data_dict_path)
dict
dat_path <- dipr_example("starwars-fwf.dat.gz")
```
The main function in the package is `read_dat()` which allows you to directly read `.dat.gz files:
```{r}
raw <- read_dat(data_path = dat_path,
data_dict = dict)
head(raw)
```
If two files share a common data dictionary you can supply a vector of filenames to the `data_path` argument and `read_dat` will combine them for you into one dataframe:
```{r}
dat_path2 <- dipr_example("starwars-fwf2.dat.gz")
raw_two_files <- read_dat(
data_path = c(dat_path, dat_path2),
data_dict = dict,
id = "file"
)
```
Working with the data.table package for data manipulation is also possible in dipr using the `read_dat_dt` function:
```{r}
raw_dt <- read_dat_dt(
data_path = dat_path,
data_dict = dict
)
```
### Data Dictionary
Data Dictionaries need to be in a data frame format that includes 'name`, 'start', 'stop', and 'length' columns (in any order):
```r
> dict
# A tibble: 64 x 4
start stop length name
<dbl> <dbl> <dbl> <chr>
```
## Project Status
Under development
## License
Copyright 2019 Province of British Columbia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.