Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R checks v2 #140

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Authors@R: c(person(
email = "[email protected]",
role = c("ctb"),
comment = c(ORCID = "0000-0002-7742-9230")),
person(given = "BlueGreen Labs",
role = c("fnd"))
person(
given = "BlueGreen Labs",
role = c("fnd"))
)
Description: Programmatic interface to the European Centre for Medium-Range
Weather Forecasts dataset web services (ECMWF; <https://www.ecmwf.int/>)
Expand Down
36 changes: 35 additions & 1 deletion R/service.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@ service <- R6::R6Class(
invisible(self)
},

exit_message = function(...) {

intro <- paste(
"Even after exiting your request is still beeing processed!\n\n"
)

options <- paste(
"- Retry downloading as soon as as completed! \n\n",
" If you close your session use the following code: \n\n",
" wf_transfer(url = '",
private$url,
"',\n path = '",
private$path,
"',\n filename = '",
private$file,
"'\n )\n\n",
"- Delete the job upon completion using:\n",
" wf_delete(\n url ='", private$url,"'\n )\n\n",
" If your session stays open you donwload or delete requests using: \n\n",
" file$download() and file$delete() *\n\n",
" [* with file from: file <- wf_request(request)] \n\n",
sep = ""
)

# combine all messages
exit_msg <- paste(intro, options, sep = "")
message(sprintf(
"- Your request has been submitted as a %s request.\n\n %s",
toupper(private$service),
exit_msg
))

},

submit = function() {
stop("not implemented")
},
Expand Down Expand Up @@ -71,7 +105,7 @@ service <- R6::R6Class(
if (private$verbose) {
# needs to change!
message(" Your download timed out, however ...\n")
# self$exit_message() # TODO
#self$exit_message() # TODO
}
}
return(self)
Expand Down
37 changes: 18 additions & 19 deletions R/wf_archetype.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@
#'
#' @examples
#' \dontrun{
#' # format an archetype function
#' ERAI <- wf_archetype(
#' request = list(stream = "oper",
#' levtype = "sfc",
#' param = "165.128/166.128/167.128",
#' dataset = "interim",
#' step = "0",
#' grid = "0.75/0.75",
#' time = "00/06/12/18",
#' date = "2014-07-01/to/2014-07-31",
#' type = "an",
#' class = "ei",
#' area = "73.5/-27/33/45",
#' format = "netcdf",
#' target = "tmp.nc"),
#' dynamic_fields = c("date", "time")
#' )
#'
#' # print output of the function with below parameters
#' str(ERA_interim("20100101", 3, 200))
#' ERA <- wf_archetype(
#' request = list(
#' dataset_short_name = "reanalysis-era5-pressure-levels",
#' product_type = "reanalysis",
#' variable = "geopotential",
#' year = "2024",
#' month = "03",
#' day = "01",
#' time = "13:00",
#' pressure_level = "1000",
#' data_format = "grib",
#' target = "download.grib"
#' ),
#' dynamic_fields = c("year", "day", "target")
#' )

#' # print output of the function with below (new) parameters
#' str(ERA(2021, 3, "new_download.grip"))
#'
#' }
wf_archetype <- function(request, dynamic_fields) {
Expand Down
11 changes: 5 additions & 6 deletions R/wf_check_request.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#' check ECMWF / CDS data requests
#'
#' Check the validity of a data request, and login credentials.
#' Check the validity of a data request by comparing the main dataset
#' to the list provided by \code{\link[ecmwfr]{wf_datasets}}
#'
#' @param user user (email address) used to sign up for the ECMWF data service,
#' used to retrieve the token set by \code{\link[ecmwfr]{wf_set_key}}
#' @param request nested list with query parameters following the layout
#' as specified on the ECMWF API page
#' @return a data frame with the determined service and url service endpoint
#' @seealso \code{\link[ecmwfr]{wf_set_key}}
#' \code{\link[ecmwfr]{wf_transfer}},\code{\link[ecmwfr]{wf_request}}
#' \code{\link[ecmwfr]{wf_transfer}},\code{\link[ecmwfr]{wf_request}},
#' \code{\link[ecmwfr]{wf_transfer}}
#' @export
#' @author Koen Hufkens
#' @importFrom memoise memoise

wf_check_request <- memoise::memoise(function(
request,
user
request
){

# Stop if not a list
Expand Down
2 changes: 1 addition & 1 deletion R/wf_dataset_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @examples
#' \dontrun{
#' # Return information
#' info <- wf_product_info("reanalysis-era5-single-levels")
#' info <- wf_dataset_info("reanalysis-era5-single-levels")
#' names(info)
#' }
#' @seealso \code{\link[ecmwfr]{wf_datasets}}.
Expand Down
2 changes: 1 addition & 1 deletion R/wf_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#'
#' \dontrun{
#' # get a list of ECMWF Data Store datasets
#' wf_datasets(service = "cems")
#' wf_datasets()
#'}

wf_datasets <- memoise::memoise(function(
Expand Down
4 changes: 4 additions & 0 deletions R/wf_delete.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#' @examples
#'
#' \dontrun{
#'
#' # demo query using a valid request (not shown)
#' file <- wf_request(request = request)
#'
#' # delete request
#' job_url <- file$get_url()
#' wf_delete(url = job_url)
Expand Down
2 changes: 1 addition & 1 deletion R/wf_get_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' in the keychain
#' @seealso \code{\link[ecmwfr]{wf_set_key}}
#' @export
#' @author Koen Kufkens
#' @author Koen Hufkens
#' @examples
#'
#' \dontrun{
Expand Down
32 changes: 16 additions & 16 deletions R/wf_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@
#'
#' \dontrun{
#' # set key
#' wf_set_key(user = "[email protected]", key = "123")
#' wf_set_key(key = "123")
#'
#' request <- list(stream = "oper",
#' levtype = "sfc",
#' param = "167.128",
#' dataset = "interim",
#' step = "0",
#' grid = "0.75/0.75",
#' time = "00",
#' date = "2014-07-01/to/2014-07-02",
#' type = "an",
#' class = "ei",
#' area = "50/10/51/11",
#' format = "netcdf",
#' target = "tmp.nc")
#' request <- list(
#' dataset_short_name = "reanalysis-era5-pressure-levels",
#' product_type = "reanalysis",
#' variable = "geopotential",
#' year = "2024",
#' month = "03",
#' day = "01",
#' time = "13:00",
#' pressure_level = "1000",
#' data_format = "grib",
#' target = "download.grib"
#' )
#'
#' # demo query
#' wf_request(request = request, user = "[email protected]")
#' wf_request(request = request)
#'
#' # Run as an RStudio Job. When finished, will create a
#' # variable named "test" in your environment with the path to
#' # the downloaded file.
#' wf_request(request = request, user = "[email protected]", job_name = "test")
#' wf_request(request = request, job_name = "test")
#'}


wf_request <- function(
request,
user = "ecmwfr",
Expand Down
3 changes: 0 additions & 3 deletions R/wf_transfer.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#' @examples
#'
#' \dontrun{
#' # set key
#' wf_set_key(key = "123")
#'
#' # request data and grab url and try a transfer
#' # (request not provided)
#' r <- wf_request(request, transfer = FALSE)
Expand Down
Loading
Loading