Skip to content

Commit 1edf7d1

Browse files
authored
Merge pull request #22 from AtlasOfLivingAustralia/development
Development
2 parents 4a298ef + b8182a8 commit 1edf7d1

20 files changed

+203
-70
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
^inst/hex.R$
99
README.Rmd
1010
^doc$
11+
^\.github$

.github/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/pkgdown.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
11+
name: pkgdown.yaml
12+
13+
permissions: read-all
14+
15+
jobs:
16+
pkgdown:
17+
runs-on: ubuntu-latest
18+
# Only restrict concurrency for non-PR jobs
19+
concurrency:
20+
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
21+
env:
22+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
23+
permissions:
24+
contents: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- uses: r-lib/actions/setup-pandoc@v2
29+
30+
- uses: r-lib/actions/setup-r@v2
31+
with:
32+
use-public-rspm: true
33+
34+
- uses: r-lib/actions/setup-r-dependencies@v2
35+
with:
36+
extra-packages: any::pkgdown, local::.
37+
needs: website
38+
39+
- name: Build site
40+
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
41+
shell: Rscript {0}
42+
43+
- name: Deploy to GitHub pages 🚀
44+
if: github.event_name != 'pull_request'
45+
uses: JamesIves/github-pages-deploy-action@v4.5.0
46+
with:
47+
clean: false
48+
branch: gh-pages
49+
folder: docs

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Depends:
2424
R (>= 4.3.0)
2525
Imports:
2626
cli,
27-
corroboree,
27+
corella,
2828
curl,
2929
dplyr,
3030
elm,
@@ -46,6 +46,7 @@ Suggests:
4646
testthat (>= 3.0.0),
4747
xml2
4848
License: MPL-2.0
49+
URL: https://galaxias.ala.org.au
4950
BugReports: https://github.com/AtlasOfLivingAustralia/galaxias/issues
5051
Maintainer: Martin Westgate <martin.westgate@csiro.au>
5152
Encoding: UTF-8

NAMESPACE

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ export(galaxias_project)
1313
export(get_validator_report)
1414
export(validate_archive)
1515
importFrom(cli,cat_line)
16+
importFrom(cli,cli_abort)
1617
importFrom(cli,cli_h2)
1718
importFrom(cli,cli_h3)
18-
importFrom(corroboree,check_occurrences)
19+
importFrom(cli,cli_inform)
20+
importFrom(cli,cli_progress_step)
21+
importFrom(cli,cli_progress_update)
22+
importFrom(corella,check_occurrences)
1923
importFrom(curl,form_data)
2024
importFrom(curl,form_file)
2125
importFrom(dplyr,bind_rows)
@@ -24,11 +28,11 @@ importFrom(dplyr,mutate)
2428
importFrom(dplyr,pull)
2529
importFrom(dplyr,select)
2630
importFrom(dplyr,slice_head)
27-
importFrom(elm,add_elm_header)
28-
importFrom(elm,check_elm)
29-
importFrom(elm,read_elm)
31+
importFrom(elm,add_eml_header)
32+
importFrom(elm,check_eml)
33+
importFrom(elm,read_md)
3034
importFrom(elm,use_metadata)
31-
importFrom(elm,write_elm)
35+
importFrom(elm,write_eml)
3236
importFrom(glue,glue)
3337
importFrom(glue,glue_collapse)
3438
importFrom(httr2,req_body_multipart)

R/build_archive.R

+33-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#'
1414
#' * One or more `csv` files such as `occurrences.csv` &/or `events.csv`.
1515
#' These will be manipulated versions of the raw dataset, which have been
16-
#' altered to use Darwin Core terms as column headers. See the `corroboree`
16+
#' altered to use Darwin Core terms as column headers. See the `corella`
1717
#' package for details.
1818
#' * A metadata statement, stored in xml using the filename `eml.xml`. The
1919
#' function `use_metadata()` from the `elm` package is a good starting point
@@ -34,12 +34,24 @@
3434
#' @export
3535
build_archive <- function(x = "data", file) {
3636
x <- get_default_directory(x)
37+
38+
progress_update("Retrieving metadata...")
3739
files_in <- find_data(x)
40+
41+
progress_update("Creating zip folder...")
3842
file_out <- get_default_file(file)
43+
44+
progress_update("Building Darwin Core Archive...")
3945
zip::zip(zipfile = file_out,
4046
files = files_in,
4147
mode = "cherry-pick")
42-
invisible(return(file_out))
48+
49+
cli::cli_alert_success("Darwin Core Archive successfully built. \nSaved as {.file {file_out}}.")
50+
cli::cli_progress_done()
51+
52+
# invisible(return(file_out)) # might need this to save
53+
54+
4355
}
4456

4557
#' Simple function to specify a zip file if no arg given
@@ -52,7 +64,7 @@ get_default_file <- function(file){
5264
glue("{getwd()}.zip")
5365
}else{
5466
if(!grepl(".zip$", file)){
55-
abort("file must end in `.zip`")
67+
abort("File must end in `.zip`.")
5668
}else{
5769
file
5870
}
@@ -62,17 +74,18 @@ get_default_file <- function(file){
6274
#' Simple function to check that a `data` directory exists if no arg given
6375
#' @importFrom rlang abort
6476
#' @importFrom rlang inform
77+
#' @importFrom cli cli_inform
6578
#' @importFrom glue glue
6679
#' @noRd
6780
#' @keywords Internal
6881
get_default_directory <- function(x){
6982
if(missing(x)){
7083
if(dir.exists("data")){
71-
inform("`x` is missing; defaulting to `data` folder")
84+
cli_inform("Missing `directory`. Defaulting to {.file data} folder.")
7285
x <- "data"
7386
}else{
74-
abort(c("`x` is missing, and `data` folder is missing",
75-
i = "please supply a folder containing required data"))
87+
abort(c("Missing `directory` and missing `data` folder.",
88+
i = "Please specify a folder containing required data."))
7689
}
7790
}else{
7891
if(!dir.exists(x)){
@@ -86,15 +99,17 @@ get_default_directory <- function(x){
8699
#' Find metadata info in a repository
87100
#' @importFrom glue glue_collapse
88101
#' @importFrom rlang abort
102+
#' @importFrom cli cli_abort
89103
#' @importFrom rlang caller_env
90104
#' @noRd
91105
#' @keywords Internal
92106
find_data <- function(directory,
93107
call = caller_env()){
94108
if(!file.exists(directory)){
95-
bullets <- c(glue("`{directory}` directory is required, but missing."),
96-
i = "use `usethis::use_data()` to add data to your project.")
97-
abort(bullets,
109+
bullets <- c(glue("Missing `directory`."),
110+
i = "Use `usethis::use_data()` to add data to your project.",
111+
x = "Can't find directory `{directory}`.")
112+
cli_abort(bullets,
98113
call = call)
99114
}
100115
accepted_names <- c("occurrences",
@@ -105,24 +120,24 @@ find_data <- function(directory,
105120
pattern = glue("^{accepted_names}.csv$"))
106121
if(length(file_list) < 1){
107122
bullets <- c("No data meeting Darwin Core requirements is given in `data`.",
108-
i = "use `add_bd_data_raw()` for examples of how to add raw data to your package",
109-
i = "use `usethis::use_data()` to add data to your package")
123+
i = "Use `add_bd_data_raw()` for examples of how to add raw data to your package.",
124+
i = "Use `usethis::use_data()` to add data to your package.")
110125
abort(bullets,
111126
call = call)
112127
}
113128

114129
if(!file.exists(glue("{directory}/meta.xml"))){
115-
bullets <- c("No schema file (`meta.xml`) is present in the specified directory.",
116-
i = "use `build_schema()` to create one")
117-
abort(bullets,
130+
bullets <- c("No schema file ({.file meta.xml}) is present in the specified directory.",
131+
i = "Use `build_schema()` to create a schema file.")
132+
cli_abort(bullets,
118133
call = call)
119134
}
120135

121136
if(!file.exists(glue("{directory}/eml.xml"))){
122-
bullets <- c("No metadata statement (`eml.xml`) is present in the specified directory.",
123-
i = "See `elm::use_metadata()` for an example metadata statement,",
124-
i = "then `build_metadata()` to convert to `eml.xml`.")
125-
abort(bullets,
137+
bullets <- c("No metadata statement ({.file eml.xml}) is present in the specified directory.",
138+
i = "See `elm::use_metadata()` for an example metadata statement.",
139+
i = "Use `build_metadata()` to convert to {.file eml.xml}.")
140+
cli_abort(bullets,
126141
call = call)
127142
}
128143

R/build_metadata.R

+17-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,33 @@
66
#' specified using the `directory` argument.
77
#'
88
#' This function is a fairly shallow wrapper on top of functionality build
9-
#' in the `elm` package, particularly `read_elm()` and `write_elm()`. You can
9+
#' in the `elm` package, particularly `read_md()` and `write_eml()`. You can
1010
#' use that package to gain greater control, or to debug problems, should you
1111
#' wish.
12-
#' @param x Path to a metadata statement stored in markdown format (.md).
12+
#' @param path Path to a metadata statement stored in markdown format (.md).
1313
#' @param file A file where the result should be saved. Defaults to
1414
#' `data/eml.xml`.
1515
#' @returns Does not return an object to the workspace; called for the side
1616
#' effect of building a file named `meta.xml` in the `data` directory.
17-
#' @importFrom elm add_elm_header
18-
#' @importFrom elm read_elm
19-
#' @importFrom elm write_elm
17+
#' @importFrom elm add_eml_header
18+
#' @importFrom elm read_md
19+
#' @importFrom elm write_eml
2020
#' @export
2121
build_metadata <- function(x = "data",
2222
file = "./data/eml.xml"){
2323
if(!file.exists(x)){
24-
abort("`x` doesn't exist in specified location.")
24+
cli::cli_abort("{.file {x}} doesn't exist in specified location.")
2525
}
2626
# import file, ensure EML metadata is added, convert to XML
27-
read_elm(x) |>
28-
add_elm_header() |>
29-
write_elm(file = file)
27+
progress_update("Reading file...")
28+
metadata_file <- read_md(x)
29+
30+
progress_update("Building xml components...")
31+
built_file <- add_eml_header(metadata_file)
32+
33+
progress_update("Writing file...")
34+
write_eml(built_file, file = file)
35+
36+
cli::cli_alert_success("Metadata successfully built. Saved as {.file /data/eml.xml}.")
37+
cli::cli_progress_done()
3038
}

R/build_schema.R

+48-8
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,55 @@
99
#' @param file (string) A file name for the resulting schema document.
1010
#' @returns Does not return an object to the workspace; called for the side
1111
#' effect of building a file named `meta.xml` in the specified directory.
12-
#' @importFrom elm write_elm
12+
#' @importFrom elm write_eml
1313
#' @importFrom glue glue
1414
#' @importFrom rlang abort
1515
#' @export
1616
build_schema <- function(x = "data",
1717
file = "./data/meta.xml") {
1818
x <- get_default_directory(x)
19-
x |>
20-
detect_dwc_files() |>
21-
detect_dwc_fields() |>
22-
add_front_matter() |>
23-
write_elm(file = file)
19+
20+
files <- detect_dwc_files(x)
21+
fields <- detect_dwc_fields(files)
22+
result <- add_front_matter(fields)
23+
24+
progress_update("Writing file...")
25+
write_eml(result, file = file)
26+
27+
cli::cli_alert_success("Schema successfully built. Saved as {.file /data/meta.xml}.")
28+
cli::cli_progress_done()
29+
}
30+
31+
#' Wait time
32+
#' @noRd
33+
#' @keywords Internal
34+
wait <- function(seconds = 1) {
35+
Sys.sleep(seconds)
36+
}
37+
38+
39+
#' Function progress message
40+
#'
41+
#' @description
42+
#' Informs users about the progress of their ongoing function steps.
43+
#'
44+
#' @importFrom cli cli_progress_step
45+
#' @importFrom cli cli_progress_update
46+
#' @noRd
47+
#' @keywords Internal
48+
progress_update <- function(message) {
49+
cli::cli_progress_step(
50+
paste0(
51+
message
52+
),
53+
spinner = TRUE
54+
)
55+
56+
for (i in 1:100) {
57+
wait(0.0001) # remove zeroes to make messages slower
58+
cli::cli_progress_update()
59+
}
60+
2461
}
2562

2663
#' Internal function to create core/extension framework for files
@@ -35,6 +72,7 @@ build_schema <- function(x = "data",
3572
#' @noRd
3673
#' @keywords Internal
3774
detect_dwc_files <- function(directory){
75+
progress_update("Detecting Darwin Core files...")
3876
available_exts <- dwc_extensions()
3977
supported_files <- available_exts |>
4078
pull("file")
@@ -47,8 +85,8 @@ detect_dwc_files <- function(directory){
4785
sep = ", ",
4886
last = " or ")
4987
bullets <- c(
50-
glue("Specified directory (\"{directory}\") does not contain any dwc-compliant csv files."),
51-
i = glue("Accepted names are {file_names}"))
88+
glue("Specified directory (\"{directory}\") does not contain any Darwin Core-compliant csv files."),
89+
i = glue("Accepted names are {file_names}."))
5290
abort(bullets)
5391
}
5492
available_exts |>
@@ -100,6 +138,7 @@ dwc_extensions <- function(){
100138
#' @noRd
101139
#' @keywords Internal
102140
detect_dwc_fields <- function(df){
141+
progress_update("Detecting Darwin Core fields in dataset...")
103142
split(df, seq_len(nrow(df))) |>
104143
map(\(x){
105144
bind_rows(create_schema_row(x),
@@ -181,6 +220,7 @@ get_field_names <- function(file){
181220
#' @noRd
182221
#' @keywords Internal
183222
add_front_matter <- function(df){
223+
progress_update("Building xml components...")
184224
front_row <- tibble(
185225
level = 1,
186226
label = "archive",

R/check_archive.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Check an archive against Darwin Core standards
22
#'
33
#' This is a wrapper to two other packages; schema and EML files (i.e. xml) are
4-
#' checked with the `elm` package; csv files are checked with the `corroboree`
4+
#' checked with the `elm` package; csv files are checked with the `corella`
55
#' package.
66
#' @param x (string) A directory containing the files to be published, or
77
#' optionally a `.zip` file built from the same (i.e. with `build_archive()`).
@@ -26,8 +26,8 @@ check_archive <- function(x = "data"){
2626
}
2727

2828
#' Internal function to check all files
29-
#' @importFrom corroboree check_occurrences
30-
#' @importFrom elm check_elm
29+
#' @importFrom corella check_occurrences
30+
#' @importFrom elm check_eml
3131
#' @importFrom purrr map
3232
#' @importFrom readr read_csv
3333
#' @noRd
@@ -38,8 +38,8 @@ check_files <- function(filenames){
3838
switch(a,
3939
"occurrences.csv" = {read_csv(a) |>
4040
check_occurrences()},
41-
"meta.xml" = {check_elm(a)},
42-
"eml.xml" = {check_elm(a)}
41+
"meta.xml" = {check_eml(a)},
42+
"eml.xml" = {check_eml(a)}
4343
)
4444
}) |>
4545
invisible()

0 commit comments

Comments
 (0)