-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
682 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: 'PR Title Checker' | ||
on: | ||
pull_request: | ||
types: [edited, opened, synchronize, reopened] | ||
branches: | ||
- main | ||
- master | ||
|
||
jobs: | ||
title-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: naveenk1223/action-pr-title@master | ||
with: | ||
regex: 'Version [0-9]+\.[0-9]+(\.[0-9]+)?$' # Regex the title should match. | ||
allowed_prefixes: ':bookmark:' # title should start with the given prefix | ||
prefix_case_sensitive: true # title prefix are case insensitive | ||
min_length: 11 # Min length of the title | ||
max_length: -1 # Max length of the title | ||
name: Check PR title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: git2rdata | ||
Title: Store and Retrieve Data.frames in a Git Repository | ||
Version: 0.4.1 | ||
Version: 0.5.0 | ||
Authors@R: c( | ||
person("Thierry", "Onkelinx", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0001-8804-4216", affiliation = "Research Institute for Nature and Forest (INBO)")), | ||
|
@@ -38,14 +38,15 @@ URL: https://ropensci.github.io/git2rdata/, | |
https://doi.org/10.5281/zenodo.1485309 | ||
BugReports: https://github.com/ropensci/git2rdata/issues | ||
Depends: | ||
R (>= 3.5.0) | ||
R (>= 4.1.0) | ||
Imports: | ||
assertthat, | ||
git2r (>= 0.23.0), | ||
methods, | ||
yaml | ||
Suggests: | ||
ggplot2, | ||
jsonlite, | ||
knitr, | ||
microbenchmark, | ||
rmarkdown, | ||
|
@@ -60,6 +61,7 @@ Roxygen: list(markdown = TRUE) | |
RoxygenNote: 7.3.2 | ||
Collate: | ||
'clean_data_path.R' | ||
'data_package.R' | ||
'datahash.R' | ||
'display_metadata.R' | ||
'git2rdata_package.R' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#' Create a Data Package for a directory of CSV files | ||
#' | ||
#' @description | ||
#' Create a `datapackage.json` file for a directory of CSV files. | ||
#' The function will look for all `.csv` files in the directory and its | ||
#' subdirectories. | ||
#' It will then create a `datapackage.json` file with the metadata of each CSV | ||
#' file. | ||
#' | ||
#' @param path the directory in which to create the `datapackage.json` file. | ||
#' @family storage | ||
#' @export | ||
#' @importFrom assertthat assert_that is.string noNA | ||
data_package <- function(path = ".") { | ||
assert_that( | ||
is.string(path), noNA(path), requireNamespace("jsonlite", quietly = TRUE) | ||
) | ||
stopifnot("`path` is not a directory" = file_test("-d", path)) | ||
|
||
data_files <- list.files(path, pattern = ".csv$", recursive = TRUE) | ||
relevant <- vapply( | ||
data_files, FUN = is_git2rdata, FUN.VALUE = logical(1), root = path | ||
) | ||
stopifnot( | ||
"no non-optimized git2rdata objects found at `path`" = any(relevant) | ||
) | ||
data_files <- data_files[relevant] | ||
|
||
list( | ||
resources = vapply( | ||
data_files, path = path, FUN = data_resource, | ||
FUN.VALUE = vector(mode = "list", length = 1) | ||
) |> | ||
unname() | ||
) |> | ||
jsonlite::toJSON(pretty = TRUE, auto_unbox = TRUE) |> | ||
writeLines(file.path(path, "datapackage.json")) | ||
return(file.path(path, "datapackage.json")) | ||
} | ||
|
||
#' @importFrom assertthat assert_that is.string noNA | ||
#' @importFrom yaml read_yaml | ||
data_resource <- function(file, path = ".") { | ||
assert_that( | ||
is.string(file), is.string(path), noNA(file), noNA(path) | ||
) | ||
stopifnot("`path` is not a directory" = file_test("-d", path)) | ||
|
||
clean_data_path(root = path, file = file)[2] |> | ||
read_yaml() -> metadata | ||
list( | ||
name = coalesce(metadata[["..generic"]][["name"]], file), path = file, | ||
"encoding" = "utf-8", format = "csv", media_type = "text/csv", | ||
hash = paste0("sha1:", metadata[["..generic"]][["data_hash"]]), | ||
schema = list( | ||
fields = vapply( | ||
names(metadata)[-1], metadata = metadata, FUN = field_schema, | ||
FUN.VALUE = vector(mode = "list", length = 1) | ||
) |> | ||
unname(), | ||
missingValues = list( | ||
c(value = metadata[["..generic"]][["NA string"]], label = "missing") | ||
) | ||
) | ||
) -> dr | ||
extra <- c("title", "description") | ||
metadata[["..generic"]][extra[extra %in% names(metadata[["..generic"]])]] |> | ||
c(dr) |> | ||
list() | ||
} | ||
|
||
field_schema <- function(x, metadata) { | ||
switch( | ||
metadata[[x]]$class, | ||
"character" = list(name = x, type = "string"), | ||
"Date" = list(name = x, type = "date"), | ||
"logical" = list( | ||
name = x, type = "boolean", trueValues = c("TRUE", "true"), | ||
falseValues = c("FALSE", "false") | ||
), | ||
"factor" = list( | ||
name = x, type = "string", categories = metadata[[x]][["labels"]], | ||
categoriesOrdered = metadata[[x]][["ordered"]] | ||
), | ||
"integer" = list(name = x, type = "integer"), | ||
"numeric" = list(name = x, type = "number"), | ||
"POSIXct" = list( | ||
name = x, type = "datetime", format = "%Y-%m-%dT%H:%M:%SZ" | ||
), | ||
stop("field_schema() can't handle ", metadata[[x]]$class) | ||
) -> fs | ||
if ("description" %in% names(metadata[[x]])) { | ||
fs$description <- metadata[[x]][["description"]] | ||
} | ||
return(list(fs)) | ||
} | ||
|
||
coalesce <- function(...) { | ||
dots <- list(...) | ||
if (length(dots) == 0) { | ||
return(NULL) | ||
} | ||
if (!is.null(dots[[1]])) { | ||
return(dots[[1]]) | ||
} | ||
do.call(coalesce, dots[-1]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.