@@ -180,16 +180,17 @@ format.EsgfQueryParam <- function(x, encode = TRUE, space = FALSE, ...) {
180180# ' input for parameter setters.
181181# '
182182# ' - \href{#method-EsgfQuery-url}{\code{EsgfQuery$url()}}: Returns the actual
183- # ' query URL.
183+ # ' query URL or the wget script URL which can be used to download all files
184+ # ' matching the given constraints..
184185# '
185186# ' - \href{#method-EsgfQuery-response}{\code{EsgfQuery$response()}}: Returns the
186- # ' acutal response of
187+ # ' actual response of
187188# ' \href{#method-EsgfQuery-count}{\code{EsgfQuery$count()}} and
188189# ' \href{#method-EsgfQuery-collect}{\code{EsgfQuery$collect()}}. It is a named
189190# ' list generated from the JSON response using [jsonlite::fromJSON()].
190191# '
191192# ' - \href{#method-EsgfQuery-print}{\code{EsgfQuery$print()}}: Print a summary
192- # ' of the current `EsgfQuery` object including the host url , the built time of
193+ # ' of the current `EsgfQuery` object including the host URL , the built time of
193194# ' facet cache and all query parameters.
194195# '
195196# ' @author Hongyuan Jia
@@ -198,7 +199,7 @@ format.EsgfQueryParam <- function(x, encode = TRUE, space = FALSE, ...) {
198199# '
199200# ' @param host The URL to the ESGF Search API service. This should be the URL of
200201# ' the ESGF search service excluding the final endpoint name. Usually
201- # ' this is `http://<hostname>/esg-search`. Default is to ses the
202+ # ' this is `http://<hostname>/esg-search`. Default is set to the
202203# ' [LLNL (Lawrence Livermore National Laboratory) Index Node](http://esgf-node.llnl.gov),
203204# ' which is `"https://esgf-node.llnl.gov/esg-search"`.
204205# '
@@ -1069,21 +1070,34 @@ EsgfQuery <- R6::R6Class("EsgfQuery",
10691070
10701071
10711072 # ' @description
1072- # ' Get the actual query URL
1073+ # ' Get the URL of actual query or wget script
1074+ # '
1075+ # ' @param wget Whether to return the URL of the wget script that can be
1076+ # ' used to download all files matching the given constraints.
1077+ # ' Default: `FALSE`.
10731078 # '
10741079 # ' @return A single string.
10751080 # '
10761081 # ' @examples
10771082 # ' \dontrun{
10781083 # ' q$url()
1084+ # '
1085+ # ' # get the wget script URL
1086+ # ' q$url(wget = TRUE)
1087+ # '
1088+ # ' # You can download the wget script using the URL directly. For
1089+ # ' # example, the code below downloads the script and save it as
1090+ # ' # 'wget.sh' in R's temporary folder:
1091+ # ' download.file(q$url(TRUE), file.path(tempdir(), "wget.sh"), mode = "wb")
1092+ # '
10791093 # ' }
1080- url = function () {
1094+ url = function (wget = FALSE ) {
1095+ assert_flag(wget )
10811096 params <- mget(ls(envir = private , pattern = " ^param_" ), envir = private )
10821097 names(params ) <- gsub(" ^param_" , " " , names(params ))
1083- query_build(private $ url_host , params )
1098+ query_build(private $ url_host , params , type = if ( wget ) " wget " else " search " )
10841099 },
10851100
1086- 10871101 # ' @description
10881102 # ' Send a query of facet counting and fetch the results
10891103 # '
@@ -1201,7 +1215,7 @@ EsgfQuery <- R6::R6Class("EsgfQuery",
12011215 # ' Print a summary of the current `EsgfQuery` object
12021216 # '
12031217 # ' `$print()` gives the summary of current `EsgfQuery` object including
1204- # ' the host url , the built time of facet cache and all query parameters.
1218+ # ' the host URL , the built time of facet cache and all query parameters.
12051219 # '
12061220 # ' @return The `EsgfQuery` object itself, invisibly.
12071221 # '
@@ -1389,11 +1403,14 @@ query_build <- function(host, params, type = "search") {
13891403 # skip empty parameter
13901404 params <- params [! vapply(params , is.null , logical (1L ))]
13911405
1406+ if (type == " wget" ) {
1407+ params <- params [! names(params ) %in% c(" type" , " format" )]
1408+ }
1409+ 13921410 if (! length(params )) return (NULL )
13931411
13941412 paste0(
1395- sprintf(" %s/search?" , host ),
1396- if (type == " wget" ) " wget" ,
1413+ sprintf(" %s/%s?" , host , type ),
13971414 paste(vapply(params , format.EsgfQueryParam , FUN.VALUE = " " ), collapse = " &" )
13981415 )
13991416}
0 commit comments