Skip to content

Commit f2f3bf6

Browse files
remove dependency on rapiclient fork
1 parent 17815e4 commit f2f3bf6

File tree

7 files changed

+47
-49
lines changed

7 files changed

+47
-49
lines changed

R/iidda.api/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: iidda.api
22
Title: IIDDA API
3-
Version: 0.2.1
3+
Version: 0.3.0
44
Authors@R:
55
person("Steve", "Walker", , "[email protected]", role = c("aut", "cre"))
66
Description: R Bindings for the IIDDA API.

R/iidda.api/NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ importFrom(iidda,parse_columns)
1919
importFrom(iidda,rm_trailing_slash)
2020
importFrom(rapiclient,get_api)
2121
importFrom(rapiclient,get_operations)
22-
importFrom(rapiclient,set_default_args_list)
2322
importFrom(readr,cols)
2423
importFrom(stats,setNames)
2524
importFrom(utils,assignInNamespace)

R/iidda.api/R/bindings.R

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ production = NULL
1919
#' @importFrom stats setNames
2020
#' @importFrom readr cols
2121
#' @importFrom httr content
22-
#' @importFrom rapiclient get_api get_operations set_default_args_list
22+
#' @importFrom rapiclient get_api get_operations
2323
#' @importFrom iidda list_xpath rm_trailing_slash
2424
#' @importFrom utils browseURL
2525

@@ -73,7 +73,7 @@ handle_iidda_response <- function(x) {
7373
}
7474

7575
make_api_obj = function(api_url, base_path, type) {
76-
try(
76+
api_obj = try(
7777
rapiclient::get_api(
7878
url = file.path(
7979
iidda::rm_trailing_slash(file.path(api_url, base_path)),
@@ -82,30 +82,10 @@ make_api_obj = function(api_url, base_path, type) {
8282
),
8383
silent = TRUE
8484
)
85-
}
86-
87-
our_rapiclient_fork = function() {
88-
## look for a zero-byte file in the rapiclient package. the
89-
## existence of this file would indicate that the user has
90-
## the our fork of rapiclient that supports passing vectors.
91-
file.exists(system.file("canmod", package = "rapiclient"))
92-
}
93-
msg_rapiclient = function() {
94-
c(
95-
"Your installation of rapiclient does not support passing "
96-
, "vectors to the arguments of iidda.api functions. "
97-
, "If you wish to pass vectors, please follow installation "
98-
, "instructions for rapiclient here: "
99-
, "https://canmod.r-universe.dev/rapiclient"
100-
)
101-
}
102-
check_rapiclient = function() {
103-
if (!our_rapiclient_fork()) warning(msg_rapiclient())
85+
return(api_obj)
10486
}
10587

10688
make_ops_list = function(api_url, base_path, type) {
107-
check_rapiclient()
108-
10989
summary_to_function_name = function(x) {
11090
gsub(pattern = " ", replacement = "_", tolower(x))
11191
}
@@ -141,7 +121,7 @@ make_ops_list = function(api_url, base_path, type) {
141121
}
142122

143123
for (name in names(raw_requests)) {
144-
raw_requests[[name]] <- rapiclient::set_default_args_list(
124+
raw_requests[[name]] <- set_default_args_list(
145125
raw_requests[[name]],
146126
parameter_list(name)
147127
)
@@ -158,7 +138,14 @@ make_ops_list = function(api_url, base_path, type) {
158138
post_request_names,
159139
get_request_names
160140
)
161-
setNames(raw_requests, request_names)
141+
requests = setNames(raw_requests, request_names)
142+
143+
## use our .api_args function, instead of rapiclient's
144+
for (method in names(requests)) {
145+
assign(".api_args", .api_args, environment(requests[[method]]))
146+
}
147+
148+
return(requests)
162149
}
163150

164151
#' IIDDA API Operations

R/iidda.api/R/featured.R

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ NULL
2525
#' , basal_disease = "poliomyelitis"
2626
#' , period_end_date = "1950-01-01..1959-12-31"
2727
#' )
28+
#' head(atlantic_polio_1950s)
2829
#'
2930
#' @export
3031
featured_data = function(dataset_id, ...) {
@@ -60,33 +61,21 @@ featured_data = function(dataset_id, ...) {
6061
, dataset_ids = dataset_id
6162
)
6263
args_filter = args_filter[cnames_good]
63-
if (!our_rapiclient_fork()) {
64-
arg_lengths = vapply(args_filter, length, integer(1L))
65-
if (any(arg_lengths > 1L)) stop(msg_rapiclient())
66-
}
6764
args = c(args, args_filter)
6865
do.call(ops_staging$filter, args)[ , cnames_data, drop = FALSE]
6966
}
7067

7168
roxygen_featured_params = function() {
72-
if (!our_rapiclient_fork()) {
73-
vec = c(
74-
"ERROR: Instruction list is not available because the following "
75-
, "issue occurred when building the package documentation. "
76-
, msg_rapiclient()
77-
)
78-
} else {
79-
filter_params = try(attributes(ops_staging$filter)$definition$parameters)
80-
if (inherits(filter_params, "try-error")) {
81-
filter_params = cached_api_list$staging$paths$`/filter`$get$parameters
82-
}
83-
names(filter_params) = vapply(filter_params, \(x) x$name, character(1L))
84-
exclude = c("resource_type", "response_type", "dataset_ids")
85-
pnames = setdiff(names(filter_params), exclude)
86-
filter_params = filter_params[pnames]
87-
pdesc = vapply(filter_params, \(x) x$description, character(1L))
88-
vec = sprintf("\n* %s : %s", pnames, pdesc)
69+
filter_params = try(attributes(ops_staging$filter)$definition$parameters)
70+
if (inherits(filter_params, "try-error")) {
71+
filter_params = cached_api_list$staging$paths$`/filter`$get$parameters
8972
}
73+
names(filter_params) = vapply(filter_params, \(x) x$name, character(1L))
74+
exclude = c("resource_type", "response_type", "dataset_ids")
75+
pnames = setdiff(names(filter_params), exclude)
76+
filter_params = filter_params[pnames]
77+
pdesc = vapply(filter_params, \(x) x$description, character(1L))
78+
vec = sprintf("\n* %s : %s", pnames, pdesc)
9079
paste(vec, collapse = "")
9180
}
9281

R/iidda.api/R/rapiclient.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# modified versions of functions from rapiclient. allows us to depend
2+
# on official rapiclient and not our fork of it.
3+
4+
.api_args = function(formals, environment) {
5+
arg_names <- if (is.null(names(formals))) character() else names(formals)
6+
arg_names <- arg_names[!arg_names %in% c("...", ".__body__")]
7+
args <- mget(arg_names, environment)
8+
expand_url_args = function(x) {
9+
if (is.null(x)) return(x) ## silence warning about passing NULL to structure
10+
structure(
11+
do.call(c, lapply(x, function(z) as.list(z)))
12+
, names = rep(names(x), sapply(x, length))
13+
)
14+
}
15+
expand_url_args(args)
16+
}
17+
18+
set_default_args_list <- function (f, arguments) {
19+
saved_attributes = attributes(f)
20+
formals(f)[names(arguments)] <- arguments
21+
attributes(f) = saved_attributes
22+
f
23+
}

R/iidda.api/R/zzz.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"Please re-establish connectivity, restart R, and try again."
1313
)
1414
}
15-
check_rapiclient() ## some stuff won't work if you don't use the canmod fork
1615
messages = lapply(messages, MakeMessage)
1716
ops = suppressWarnings({try(do.call(make_ops_list, production), silent = TRUE)})
1817
ops_local = suppressWarnings({try(do.call(make_ops_list, local), silent = TRUE)})

R/iidda.api/man/featured.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)