https://github.com/poissonconsulting/chktemplate
An R package to work with excel templates for data upload
https://github.com/poissonconsulting/chktemplate
Last synced: 22 days ago
JSON representation
An R package to work with excel templates for data upload
- Host: GitHub
- URL: https://github.com/poissonconsulting/chktemplate
- Owner: poissonconsulting
- License: other
- Created: 2020-08-19T19:53:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-20T22:19:07.000Z (3 months ago)
- Last Synced: 2025-02-01T18:42:58.145Z (3 months ago)
- Language: R
- Homepage: https://poissonconsulting.github.io/chktemplate/
- Size: 1.54 MB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
- jimsghstars - poissonconsulting/chktemplate - An R package to work with excel templates for data upload (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# chktemplate
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://github.com/poissonconsulting/chktemplate/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/poissonconsulting/chktemplate)Work with data template by turning them into a human-readable format and confirm the data follows all the requirements.
## Installation
You can install the development version from [GitHub](https://github.com/poissonconsulting/chktemplate) with:
``` r
# install.packages("remotes")
remotes::install_github("poissonconsulting/chktemplate")
```## Demonstration
```{r}
library(chktemplate)
```### Convert Template to be Human Readable
The templates need to be written in code but this is not very readable for a user.
Use the `template_human()` function to convert the template into a human readable form.```{r}
# subset the first four columns so example fits on page
# code version of the template
demo_template_fish_exploit$outing[1:4]
# human readable version of the template
template_human(demo_template_fish_exploit$outing[1:4])
```### Check Data Against Template Requirements
Pass data and the template to `check_data_format()` to ensure the data follows all the rules and requirements of the template.
It can check whether all columns are supplied, the type of the column, the range of values, the primary key, uniqueness of the column, and joins between tables.```{r}
outing <- data.frame(
outing_id = c(1L, 2L, 3L),
site_name = c("Pretty Bay", "Pretty Bay", "Pretty Bay"),
year = c(2010, 2010, 2010),
month = c(07, 07, 07),
day = c(15, 16, 17),
hour_start = c(9L, 11L, 8L),
minute_start = c(0, 0, 0),
guide = c("JT", "JT", "JT"),
rod_count = c(2, 3, 2),
comment = c(NA_character_, NA_character_, NA_character_)
)data <- check_data_format(
outing = outing,
template = demo_template_fish_exploit
)
```The `complete` argument checks if all tables are present.
```{r}
site <- data.frame(
site_name = c("Pretty Bay", "Ugly Bay", "Green Bay")
)outing <- data.frame(
outing_id = c(1L, 2L, 3L),
site_name = c("Pretty Bay", "Pretty Bay", "Pretty Bay"),
year = c(2010, 2010, 2010),
month = c(7, 7, 7),
day = c(15, 16, 17),
hour_start = c(9L, 11L, 8L),
minute_start = c(0, 0, 0),
guide = c("JT", "JT", "JT"),
rod_count = c(2, 3, 2),
comment = c(NA_character_, NA_character_, NA_character_)
)capture <- data.frame(
outing_id = c(1L, 2L, 3L),
guide = c("JT", "JT", "JT"),
hour = c(7L, 8L, 7L),
minute = c(0L, 30L, 45L),
easting = c(1031941, 1031971, 1031944),
northing = c(892421, 892451, 892429),
species = c("BT", "CT", "CT"),
forklength_mm = c(100, 700, 300),
weight_kg = c(0.5, 10, 4),
tbartag_number1 = c(78, 91, 82),
tbartag_number2 = c(14, 18, 21),
released = c("yes", "no", "no")
)recapture <- data.frame(
year = c(2009, 2009),
month = c(10, 10),
day = c(14, 15),
angler = c("Dave John", "John Smith"),
contact = c("250-637-9999", "250-557-1414"),
tbartag_number1 = c(92, 57),
tbartag_number2 = c(10, 12)
)data <- check_data_format(
site = site,
outing = outing,
capture = capture,
recapture = recapture,
template = demo_template_fish_exploit,
complete = TRUE
)
```Joins are only checked if `join` is set to `TRUE`.
```{r}
site <- data.frame(
site_name = c("Pretty Bay", "Ugly Bay", "Green Bay")
)outing <- data.frame(
outing_id = c(1L, 2L, 3L),
site_name = c("Pretty Bay", "Pretty Bay", "Pretty Bay"),
year = c(2010, 2010, 2010),
month = c(7, 7, 7),
day = c(15, 16, 17),
hour_start = c(9L, 11L, 8L),
minute_start = c(0, 0, 0),
guide = c("JT", "JT", "JT"),
rod_count = c(2, 3, 2),
comment = c(NA_character_, NA_character_, NA_character_)
)capture <- data.frame(
outing_id = c(1L, 2L, 3L),
guide = c("JT", "JT", "JT"),
hour = c(7L, 8L, 7L),
minute = c(0L, 30L, 45L),
easting = c(1031941, 1031971, 1031944),
northing = c(892421, 892451, 892429),
species = c("BT", "CT", "CT"),
forklength_mm = c(100, 700, 300),
weight_kg = c(0.5, 10, 4),
tbartag_number1 = c(78, 91, 82),
tbartag_number2 = c(14, 18, 21),
released = c("yes", "no", "no")
)recapture <- data.frame(
year = c(2009, 2009),
month = c(10, 10),
day = c(14, 15),
angler = c("Dave John", "John Smith"),
contact = c("250-637-9999", "250-557-1414"),
tbartag_number1 = c(92, 57),
tbartag_number2 = c(10, 12)
)data <- check_data_format(
site = site,
outing = outing,
capture = capture,
recapture = recapture,
template = demo_template_fish_exploit,
complete = TRUE,
join = TRUE
)
```## Template Requirements
In the templates the first column needs to be the name column which is a special column.
The name column sets out the rules for the template.
No other column can be called name.Description of each row:
- name: column names
- example: sample value, optional
- description: written description of the column
- chk: range, type, missing value and set checks, see [chk::chk_values](https://poissonconsulting.github.io/chk/reference/check_values.html) for how values are checked
- pkey: primary key, set values as `TRUE`, can be a combination of columns
- unique: column has to be unique, set values as `TRUE`, optional
- join1: place parent table name in the variable(s) that should be the `by` argument of join, optional
- a join row can only join to one table, to join to multiple tables add more join rows like join2, join3, etc.
- Check `chktemplate::demo_template_count` template for an example of a table with multiple join rows.## Code of Conduct
Please note that the `chktemplate` project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.