Skip to content

Commit

Permalink
add basic query function for chronontology
Browse files Browse the repository at this point in the history
  • Loading branch information
lsteinmann committed Sep 1, 2024
1 parent 2023a48 commit 642223b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Description: This package provides convenience functions that are helpful
License: GPL (>= 3)
Depends:
R (>= 3.3),
jsonlite
jsonlite,
crul
Suggests:
covr,
dplyr,
Expand All @@ -27,5 +28,5 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(duplicate_by)
export(from_chronontology)
export(group_periods)
export(make_chrongler_conc)
export(query_chronontology)
export(ungroup_periods)
importFrom(jsonlite,fromJSON)
importFrom(utils,read.csv)
35 changes: 35 additions & 0 deletions R/query_chronontology.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' Basic Query for iDAI.chronontology
#'
#'
#'
#' @param value (chr) The value you want to search for in all chronontology-periods.
#'
#' @return A list of results as handed out by iDAI.chronontology.
#'
#' @export
#'
#' @examples
#' roman_periods <- query_chronontology(value = "roman")
#' names <- unlist(lapply(roman_periods, function(x) x$resource$names$en))
query_chronontology <- function(value = "roman") {
stopifnot(is.character(value))

url <- "https://chronontology.dainst.org"
headers <- list(`Content-Type` = "application/json",
Accept = "application/json")
ChronClient <- crul::HttpClient$new(url = url, headers = headers)

response <- ChronClient$get(path = paste0('data/period/?q=', value, '&size=1'))
response <- response$parse("UTF-8")
list <- jsonlite::fromJSON(response, FALSE)

if (list$total > length(list$results)) {
response <- ChronClient$get(path = paste0('data/', type, '/?q=', value, '&size=', list$total))
response <- response$parse("UTF-8")
list <- jsonlite::fromJSON(response, FALSE)
}

result <- list$results

return(result)
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<!-- badges: end -->

# chrongler wrangles categorical chronological data

This package provides convenience functions that are helpful for working with archaeological or historical data, where chronological information is stored as a 'period' (categorical values that may indicate chronology in one way or another). The functions are purely for formatting and 'wrangling' such data, and do not contain any means of analysis or further processing.

# Installation

chrongler is not on CRAN. You can install the current version from GitHub using:
``` r
remotes::install_github("lsteinmann/chrongler", build_vignettes = TRUE)
Expand All @@ -23,6 +25,7 @@ Using chrongler (and a concordance of periods and their grouping and absolute da
* download the data for one period from [iDAI.chronontology](https://chronontology.dainst.org/) (`from_chronontology()`, it's a bit of a work in progress...)

The inaccurately named "example_workflow"-vignette explains the functions and especially setting up the concordance in detail, see:

``` r
browseVignettes("chrongler")
```
Expand Down
21 changes: 21 additions & 0 deletions man/query_chronontology.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 642223b

Please sign in to comment.