Closed aedin closed 2 weeks ago
Hi Aedin, @aedin
This should work with the latest version of rapiclient
: '0.1.7'
. It should be posted on CRAN soon. If not, you can install the GitHub repo here.
Note that for APIs without a file extension, it is best to enter one manually via the ext
argument. See example below.
suppressPackageStartupMessages({
library(rapiclient)
})
packageVersion("rapiclient")
#> [1] '0.1.7'
api_url <- "https://clinicaltrials.gov/api/oas/v2"
CT_api <- get_api(api_url, ext = "yml")
#> Warning in get_api(api_url, ext = "yml"): Missing Swagger Specification version
operations <- get_operations(CT_api)
operations$fetchStudy(nctId="NCT04000165")
#> Response [https://clinicaltrials.gov/studies/NCT04000165]
#> Date: 2024-09-30 14:58
#> Status: 200
#> Content-Type: text/html
#> Size: 74.6 kB
#> <!DOCTYPE html>
#>
#> <html lang="en" data-critters-container>
#> <head><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
#> <meta charset="UTF-8">
#> <script type="text/javascript">
#> window.ncbi_startTime = new Date();
#> </script>
#> <meta http-equiv="X-UA-Compatible" content="IE=edge">
#>
#> ...
Created on 2024-09-30 with reprex v2.1.1
Thanks a million, works perfectly
I am sure I am missing something simple. Apologizes if this is the case.
Clinicaltrials.gov have a new API (https://clinicaltrials.gov/data-api/api) with API specifications in yaml.
api_url <- "https://clinicaltrials.gov/api/oas/v2" # URL to the specifications in yaml CT_api <- rapiclient:::get_api(api_url) # failed as it expects .yaml file extension CT_api <- rapiclient:::get_api_yaml(api_url). # works, but later fails as
operations <- get_operations(CT_api) operations$fetchStudy(nctId="NCT04000165") # Error, missing URL
Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
attached base packages: [1] stats graphics grDevices utils datasets methods
[7] base
other attached packages: [1] httr2_1.0.4 jsonlite_1.8.9 httr_1.4.7 rapiclient_0.1.6
loaded via a namespace (and not attached): [1] R6_2.5.1 xfun_0.44 magrittr_2.0.3
[4] rappdirs_0.3.3 glue_1.7.0 knitr_1.45
[7] lifecycle_1.0.4 cli_3.6.3 pkgload_1.3.4
[10] compiler_4.3.3 highr_0.11 rstudioapi_0.15.0 [13] tools_4.3.3 curl_5.2.3 evaluate_0.23
[16] mime_0.12 yaml_2.3.8 rlang_1.1.4
Thanks