Skip to content

Commit d72b733

Browse files
committed
add vdat_template
1 parent 3de8791 commit d72b733

File tree

7 files changed

+115
-11
lines changed

7 files changed

+115
-11
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: rvdat
22
Title: Lightweight access to VDAT shell commands
3-
Version: 0.0.0.9005
3+
Version: 0.0.0.9100
44
Authors@R: c(
55
person("Michael", "O'Brien", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-1420-6395"))

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(skip_example_on_runiverse)
55
export(vdat_call)
66
export(vdat_here)
77
export(vdat_inspect)
8+
export(vdat_template)
89
export(vdat_to_csv)
910
export(vdat_to_folder)
1011
export(vdat_to_json)

R/vdat_template.R

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' Return description fields ("template") of different VDAT data types and/or files
2+
#'
3+
#' @param format file format of the template. Currently only accepts "csv.fathom";
4+
#' here for future compatibility.
5+
#' @param print logical. Defaults to FALS.E Print the output to console?
6+
#' @param ... arguments passed to [`vdat_call`].
7+
#'
8+
#' @export
9+
10+
vdat_template <- function(
11+
format = 'csv.fathom',
12+
print = FALSE,
13+
...
14+
){
15+
16+
format <- match.arg(format, 'csv.fathom')
17+
18+
shell_out <- vdat_call(
19+
what = c(
20+
"template",
21+
paste0('--format=', format)
22+
),
23+
pass_error = TRUE,
24+
print = print,
25+
...
26+
)
27+
28+
template <- rawToChar(shell_out$stdout)
29+
template <- unlist(
30+
strsplit(
31+
template,
32+
'\r\n'
33+
)
34+
)
35+
template <- strsplit(template, ',')[-c(1:2)]
36+
37+
names(template) <- sapply(template, `[`, 1)
38+
39+
lapply(template, `[`, -1)
40+
}

README.Rmd

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ remotes::install_github("mhpob/rvdat")
7474

7575
- [ ] Sensor values
7676
- [ ] Logging
77-
- Create template for
78-
- [ ] CSV
79-
- [ ] JSON
8077
- [ ] Look for `vdat.exe`
8178

8279
### Completed
@@ -89,6 +86,7 @@ remotes::install_github("mhpob/rvdat")
8986
- [X] Output location
9087
- [X] Time correction
9188
- [X] Inspect content of file
89+
- [X] Create CSV template
9290

9391
### Won't add (for now)
9492

@@ -98,6 +96,9 @@ remotes::install_github("mhpob/rvdat")
9896
- Removed from `vdat.exe` in spring 2023. Left to user.
9997
- [ ] ~~Time offset~~
10098
- Won't add; subtracts a number of hours from the time without being DST-aware.
99+
- [ ] ~~JSON template~~
100+
- The `json.rxlog` and `vfwp` formats noted in the help documentation return
101+
as invalid.
101102

102103

103104
## Using the package

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ remotes::install_github("mhpob/rvdat")
8888

8989
- [ ] Sensor values
9090
- [ ] Logging
91-
- Create template for
92-
- [ ] CSV
93-
- [ ] JSON
9491
- [ ] Look for `vdat.exe`
9592

9693
### Completed
@@ -103,6 +100,7 @@ remotes::install_github("mhpob/rvdat")
103100
- [x] Output location
104101
- [x] Time correction
105102
- [x] Inspect content of file
103+
- [x] Create CSV template
106104

107105
### Won’t add (for now)
108106

@@ -114,6 +112,9 @@ remotes::install_github("mhpob/rvdat")
114112
- [ ] ~~Time offset~~
115113
- Won’t add; subtracts a number of hours from the time without being
116114
DST-aware.
115+
- [ ] ~~JSON template~~
116+
- The `json.rxlog` and `vfwp` formats noted in the help documentation
117+
return as invalid.
117118

118119
## Using the package
119120

@@ -142,10 +143,10 @@ Convert a VRL to CSV:
142143
``` r
143144
## vdat_to_csv("SOME-VDAT-FILE")
144145
#> ✔ File converted:
145-
#> C:\Users\darpa2\AppData\Local\Temp\RtmpQnIw42/readme_files/HR2-180 461396
146+
#> C:\Users\darpa2\AppData\Local\Temp\RtmpIdz6ds/readme_files/HR2-180 461396
146147
#> 2021-04-20 173145.vdat
147148
#> ℹ File saved in:
148-
#> C:\Users\darpa2\AppData\Local\Temp\RtmpQnIw42/readme_files/HR2-180 461396
149+
#> C:\Users\darpa2\AppData\Local\Temp\RtmpIdz6ds/readme_files/HR2-180 461396
149150
#> 2021-04-20 173145.csv
150151
```
151152

@@ -154,10 +155,10 @@ Convert a VRL to a folder of CSVs split by data type:
154155
``` r
155156
## vdat_to_folder("SOME-VDAT-FILE")
156157
#> ✔ File converted:
157-
#> C:\Users\darpa2\AppData\Local\Temp\RtmpQnIw42/readme_files/HR2-180 461396
158+
#> C:\Users\darpa2\AppData\Local\Temp\RtmpIdz6ds/readme_files/HR2-180 461396
158159
#> 2021-04-20 173145.vdat
159160
#> ℹ Files saved in:
160-
#> C:\Users\darpa2\AppData\Local\Temp\RtmpQnIw42/readme_files/HR2-180 461396
161+
#> C:\Users\darpa2\AppData\Local\Temp\RtmpIdz6ds/readme_files/HR2-180 461396
161162
#> 2021-04-20 173145.csv-fathom-split
162163
## list.files("SOME-VDAT-FILE.csv-fathom-split")
163164
#> [1] "ATTITUDE.csv" "BATTERY.csv" "CFG_CHANNEL.csv"

man/vdat_template.Rd

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-vdat_template.R

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
test_that("error if not csv", {
2+
expect_error(
3+
vdat_template(format = 'json'),
4+
'\'arg\' should be "csv.fathom"'
5+
)
6+
})
7+
8+
test_that("partial matching works", {
9+
expect_equal(
10+
vdat_template(),
11+
vdat_template(format = 'csv')
12+
)
13+
})
14+
15+
test_that("print works", {
16+
expect_output(
17+
vdat_template(print = TRUE)
18+
)
19+
})
20+
21+
test_that("correct types", {
22+
template <- vdat_template()
23+
24+
expect_type(template, 'list')
25+
26+
expect_length(template, 45)
27+
expect_named(
28+
template,
29+
c("ATTITUDE_DESC", "BATTERY_DESC", "CFG_CHANNEL_DESC", "CFG_RECEIVER_HR3_DESC",
30+
"CFG_STATION_DESC", "CFG_STUDY_DESC", "CFG_TRANSMITTER_DESC", "CLOCK_REF_DESC",
31+
"CLOCK_SET_DESC", "DATA_ERROR_DESC", "DATA_SOURCE_FILE_DESC", "DEPTH_DESC",
32+
"DEPTH_STATS_DESC", "DET_DESC", "DET_HTI_DESC", "DET_FILTER_DESC",
33+
"DET_SENS_DESC", "DIAG_DESC", "DIAG_FAST_DESC", "DIAG_HR2_DESC",
34+
"DIAG_HR3_DESC", "DIAG_VR2W_DESC", "DIAG_VR2W_INTERIM_DESC", "DIAG_VR2AR_DESC",
35+
"DIAG_VR2AR_INTERIM_DESC", "DIAG_VR2TX_DESC", "DIAG_VR2TX_INTERIM_DESC",
36+
"DIAG_VR4_DESC", "EVENT_DESC", "EVENT_FAULT_DESC", "EVENT_INIT_DESC",
37+
"EVENT_OFFLOAD_DESC", "HEALTH_HR2_DESC", "HEALTH_HR3_DESC", "HEALTH_VR2AR_DESC",
38+
"HEALTH_VR2TX_DESC", "HEALTH_VR2W_DESC", "HEALTH_VR4_DESC", "NOISE_DESC",
39+
"NOISE_STATS_VR2AR_DESC", "NOISE_STATS_VR2TX_DESC", "PING_DESC", "TEMP_DESC",
40+
"TEMP_STATS_DESC", "XPND_EVENT_DESC")
41+
)
42+
})

0 commit comments

Comments
 (0)