Skip to content

Commit

Permalink
Added csl_fields data prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Jan 26, 2021
1 parent ed7777b commit 954643c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ njtierney
^\.httr-oauth$
^_pkgdown\.yml$
^CRAN-RELEASE$
^data-raw$
Binary file added R/sysdata.rda
Binary file not shown.
25 changes: 25 additions & 0 deletions data-raw/csl_fields.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
csl_types <- jsonlite::read_json("https://resource.citationstyles.org/schema/latest/input/json/csl-data.json")
csl_fields <- csl_types$items$properties
csl_field_type <- function(x) {
type <- x[["type"]][[1]]
if(is.null(type)) type <- sub("#/definitions/", "", x[["$ref"]], fixed = TRUE)
if(type == "array") {
x <- csl_field_type(x[["items"]])
if(vec_is(x, csl_names())) {
return(vctrs::new_list_of(ptype = x, class = "list_of_csl_names"))
} else {
# Too hard to convert to list_of for all types
return(list())
}
}
switch (type,
"string" = character(),
"number" = numeric(),
"name-variable" = csl_names(),
"date-variable" = csl_dates(),
"object" = list()
)
}
csl_fields <- tibble::as_tibble(lapply(csl_fields, csl_field_type))

usethis::use_data(csl_fields, overwrite = TRUE, internal = TRUE)

0 comments on commit 954643c

Please sign in to comment.