├── R ├── AnVILBase-package.R ├── Platform-class.R ├── avworkflow-generics.R ├── has_avworkspace-generics.R ├── avworkflow-methods.R ├── has_avworkspace-methods.R ├── avnotebooks-generics.R ├── avworkspace-generics.R ├── AnVILBase-generics.R ├── avtable-generics.R ├── utilities.R ├── avnotebooks-methods.R ├── Response.R ├── avworkspace-methods.R ├── AnVILBase-methods.R ├── cloud_platform.R └── avtable-methods.R ├── NEWS.md ├── man ├── Platform-class.Rd ├── avworkflow-generics.Rd ├── AnVILBase-package.Rd ├── avnotebooks-generics.Rd ├── has_avworkspace-generics.Rd ├── AnVILBase-generics.Rd ├── avbase-utilities.Rd ├── avworkspace-generics.Rd ├── avtable-generics.Rd ├── avworkflow-methods.Rd ├── has_avworkspace-methods.Rd ├── Response.Rd ├── avnotebooks-methods.Rd ├── cloud_platform.Rd ├── AnVILBase-methods.Rd ├── avworkspace-methods.Rd └── avtable-methods.Rd ├── tests ├── testthat.R └── testthat │ └── test-utilities.R ├── .gitignore ├── DESCRIPTION ├── NAMESPACE └── vignettes └── AnVILBaseIntroduction.Rmd /R/AnVILBase-package.R: -------------------------------------------------------------------------------- 1 | #' @name AnVILBase-package 2 | #' 3 | #' @title The AnVILBase package 4 | #' 5 | #' @description The `AnVILBase` package defines S4 generics for the AnVIL 6 | #' package. 7 | #' 8 | #' @import methods 9 | #' 10 | "_PACKAGE" 11 | 12 | -------------------------------------------------------------------------------- /R/Platform-class.R: -------------------------------------------------------------------------------- 1 | #' @title Virtual Class for Platform 2 | #' 3 | #' @description This is a virtual class for Platform objects. It is used to 4 | #' define the class hierarchy for Platform objects. 5 | #' 6 | #' @return Used mainly for inheritance. 7 | #' 8 | #' @exportClass Platform 9 | .Platform <- setClass("Platform") 10 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # AnVILBase 1.0.0 2 | 3 | * Added `has_avworkspace` generic and methods to check for the presence of an 4 | AnVIL workspace. 5 | * Added `avworkspace*` and `tables*` generics and methods. 6 | * Remove `avdata` generics and methods (not supported on Azure). 7 | 8 | # AnVILBase 0.99.0 9 | 10 | * Initial Bioconductor submission. 11 | -------------------------------------------------------------------------------- /man/Platform-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Platform-class.R 3 | \docType{class} 4 | \name{Platform-class} 5 | \alias{Platform-class} 6 | \alias{.Platform} 7 | \title{Virtual Class for Platform} 8 | \value{ 9 | Used mainly for inheritance. 10 | } 11 | \description{ 12 | This is a virtual class for Platform objects. It is used to 13 | define the class hierarchy for Platform objects. 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(AnVILBase) 11 | 12 | test_check("AnVILBase") 13 | -------------------------------------------------------------------------------- /R/avworkflow-generics.R: -------------------------------------------------------------------------------- 1 | #' @name avworkflow-generics 2 | #' 3 | #' @aliases avworkflow_jobs 4 | #' 5 | #' @title All the workflow type generics for AnVIL 6 | #' 7 | #' @description These are the generics to be used by the AnVIL package. 8 | #' 9 | #' @inheritParams AnVILBase-generics 10 | #' 11 | #' @seealso [AnVILBase-generics], [avworkspace-generics], [avtable-generics] 12 | #' 13 | #' @return called for the side effect of registering generic functions 14 | #' 15 | #' @examples 16 | #' getGeneric("avworkflow_jobs") 17 | #' 18 | NULL 19 | 20 | # avworkflow_jobs ---------------------------------------------------------- 21 | 22 | #' @rdname avworkflow-generics 23 | #' @export 24 | setGeneric( 25 | "avworkflow_jobs", 26 | function(..., platform) standardGeneric("avworkflow_jobs"), 27 | signature = "platform" 28 | ) 29 | -------------------------------------------------------------------------------- /man/avworkflow-generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avworkflow-generics.R 3 | \name{avworkflow-generics} 4 | \alias{avworkflow-generics} 5 | \alias{avworkflow_jobs} 6 | \title{All the workflow type generics for AnVIL} 7 | \usage{ 8 | avworkflow_jobs(..., platform) 9 | } 10 | \arguments{ 11 | \item{...}{Arguments passed to the methods.} 12 | 13 | \item{platform}{A Platform derived class indicating the AnVIL environment, 14 | currently, \code{azure} and \code{gcp} classes are compatible.} 15 | } 16 | \value{ 17 | called for the side effect of registering generic functions 18 | } 19 | \description{ 20 | These are the generics to be used by the AnVIL package. 21 | } 22 | \examples{ 23 | getGeneric("avworkflow_jobs") 24 | 25 | } 26 | \seealso{ 27 | \link{AnVILBase-generics}, \link{avworkspace-generics}, \link{avtable-generics} 28 | } 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | .RDataTmp 8 | 9 | # User-specific files 10 | .Ruserdata 11 | 12 | # Example code in package build process 13 | *-Ex.R 14 | 15 | # Output files from R CMD build 16 | /*.tar.gz 17 | 18 | # Output files from R CMD check 19 | /*.Rcheck/ 20 | 21 | # RStudio files 22 | .Rproj.user/ 23 | *.Rproj 24 | 25 | # produced vignettes 26 | vignettes/*.html 27 | vignettes/*.pdf 28 | 29 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 30 | .httr-oauth 31 | 32 | # knitr and R markdown default cache directories 33 | *_cache/ 34 | /cache/ 35 | 36 | # Temporary files created by R markdown 37 | *.utf8.md 38 | *.knit.md 39 | 40 | # R Environment Variables 41 | .Renviron 42 | 43 | # pkgdown site 44 | docs/ 45 | 46 | # translation temp files 47 | po/*~ 48 | 49 | # RStudio Connect folder 50 | rsconnect/ 51 | 52 | -------------------------------------------------------------------------------- /man/AnVILBase-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AnVILBase-package.R 3 | \docType{package} 4 | \name{AnVILBase-package} 5 | \alias{AnVILBase} 6 | \alias{AnVILBase-package} 7 | \title{The AnVILBase package} 8 | \description{ 9 | The \code{AnVILBase} package defines S4 generics for the AnVIL 10 | package. 11 | } 12 | \seealso{ 13 | Useful links: 14 | \itemize{ 15 | \item \url{https://github.com/Bioconductor/AnVILBase} 16 | \item Report bugs at \url{https://github.com/Bioconductor/AnVILBase/issues} 17 | } 18 | 19 | } 20 | \author{ 21 | \strong{Maintainer}: Marcel Ramos \email{marcel.ramos@sph.cuny.edu} (\href{https://orcid.org/0000-0002-3242-0582}{ORCID}) 22 | 23 | Authors: 24 | \itemize{ 25 | \item Martin Morgan (\href{https://orcid.org/0000-0002-5874-8148}{ORCID}) [contributor] 26 | } 27 | 28 | Other contributors: 29 | \itemize{ 30 | \item NIH NHGRI U24HG004059 [funder] 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/testthat/test-utilities.R: -------------------------------------------------------------------------------- 1 | test_that("avworkspaces_clean() preserves leading and trailing spaces", { 2 | ## add intentional spaces in workspace.name 3 | testws <- tibble::tibble( 4 | workspace.name = " a test workspace ", 5 | workspace.lastModified = "2023-06-26T21:17:26.343Z", 6 | workspace.createdBy = "test.bioc@gmail.com", 7 | workspace.namespace = "bioconductor-rpci-anvil", 8 | accessLevel = "READER", 9 | extraCol = TRUE 10 | ) 11 | restbl <- testws 12 | ## for testing names 13 | coi <- c("name", "lastModified", "createdBy", "namespace", "accessLevel") 14 | names(restbl) <- coi 15 | ## for testing select operation 16 | restbl <- restbl[, coi] 17 | ## for testing Date coercion 18 | restbl[["lastModified"]] <- as.Date(restbl[["lastModified"]]) 19 | 20 | expect_identical( 21 | avworkspaces_clean(testws), 22 | restbl 23 | ) 24 | }) 25 | 26 | -------------------------------------------------------------------------------- /R/has_avworkspace-generics.R: -------------------------------------------------------------------------------- 1 | #' @name has_avworkspace-generics 2 | #' 3 | #' @aliases has_avworkspace 4 | #' 5 | #' @title The generic for checking if the user is within an environment 6 | #' 7 | #' @description These are generics to be used by the AnVILGCP and AnVILAz 8 | #' packages. 9 | #' 10 | #' @inheritParams AnVILBase-generics 11 | #' 12 | #' @param strict `logical(1)` Whether to include a check for an existing 13 | #' `avworkspace_name()` setting. Default `FALSE`. 14 | #' 15 | #' @seealso [AnVILBase-generics], [avworkspace-generics], [avtable-generics] 16 | #' 17 | #' @return called for the side effect testing the workspace environment 18 | #' 19 | #' @examples 20 | #' getGeneric("has_avworkspace") 21 | #' 22 | NULL 23 | 24 | # has_avworkspace ---------------------------------------------------------- 25 | 26 | #' @rdname has_avworkspace-generics 27 | #' @export 28 | setGeneric( 29 | "has_avworkspace", 30 | function(strict = FALSE, ..., platform) standardGeneric("has_avworkspace"), 31 | signature = "platform" 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /man/avnotebooks-generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avnotebooks-generics.R 3 | \name{avnotebooks-generics} 4 | \alias{avnotebooks-generics} 5 | \alias{avnotebooks} 6 | \alias{avnotebooks_localize} 7 | \alias{avnotebooks_delocalize} 8 | \title{All the avnotebooks generics for AnVIL} 9 | \usage{ 10 | avnotebooks(..., platform) 11 | 12 | avnotebooks_localize(..., platform) 13 | 14 | avnotebooks_delocalize(..., platform) 15 | } 16 | \arguments{ 17 | \item{...}{Arguments passed to the methods.} 18 | 19 | \item{platform}{A Platform derived class indicating the AnVIL environment, 20 | currently, \code{azure} and \code{gcp} classes are compatible.} 21 | } 22 | \value{ 23 | called for the side effect of registering generic functions 24 | } 25 | \description{ 26 | These are the generics to be used by the AnVIL package. 27 | } 28 | \examples{ 29 | getGeneric("avnotebooks") 30 | 31 | 32 | } 33 | \seealso{ 34 | \link{AnVILBase-generics}, \link{avworkspace-generics}, \link{avtable-generics}, 35 | \link{avworkflow-generics} 36 | } 37 | -------------------------------------------------------------------------------- /man/has_avworkspace-generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/has_avworkspace-generics.R 3 | \name{has_avworkspace-generics} 4 | \alias{has_avworkspace-generics} 5 | \alias{has_avworkspace} 6 | \title{The generic for checking if the user is within an environment} 7 | \usage{ 8 | has_avworkspace(strict = FALSE, ..., platform) 9 | } 10 | \arguments{ 11 | \item{strict}{\code{logical(1)} Whether to include a check for an existing 12 | \code{avworkspace_name()} setting. Default \code{FALSE}.} 13 | 14 | \item{...}{Arguments passed to the methods.} 15 | 16 | \item{platform}{A Platform derived class indicating the AnVIL environment, 17 | currently, \code{azure} and \code{gcp} classes are compatible.} 18 | } 19 | \value{ 20 | called for the side effect testing the workspace environment 21 | } 22 | \description{ 23 | These are generics to be used by the AnVILGCP and AnVILAz 24 | packages. 25 | } 26 | \examples{ 27 | getGeneric("has_avworkspace") 28 | 29 | } 30 | \seealso{ 31 | \link{AnVILBase-generics}, \link{avworkspace-generics}, \link{avtable-generics} 32 | } 33 | -------------------------------------------------------------------------------- /man/AnVILBase-generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AnVILBase-generics.R 3 | \name{AnVILBase-generics} 4 | \alias{AnVILBase-generics} 5 | \alias{avcopy} 6 | \alias{avlist} 7 | \alias{avremove} 8 | \alias{avbackup} 9 | \alias{avrestore} 10 | \alias{avstorage} 11 | \title{All the generics for AnVIL} 12 | \usage{ 13 | avcopy(..., platform) 14 | 15 | avlist(..., platform) 16 | 17 | avremove(..., platform) 18 | 19 | avbackup(..., platform) 20 | 21 | avrestore(..., platform) 22 | 23 | avstorage(..., platform) 24 | } 25 | \arguments{ 26 | \item{...}{Arguments passed to the methods.} 27 | 28 | \item{platform}{A Platform derived class indicating the AnVIL environment, 29 | currently, \code{azure} and \code{gcp} classes are compatible.} 30 | } 31 | \value{ 32 | called for the side effect of registering generic functions 33 | } 34 | \description{ 35 | These are the generics to be used by the AnVIL package. 36 | } 37 | \examples{ 38 | getGeneric("avcopy") 39 | 40 | } 41 | \seealso{ 42 | \link{avworkspace-generics}, \link{avtable-generics}, \link{avworkflow-generics} 43 | } 44 | -------------------------------------------------------------------------------- /man/avbase-utilities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{avbase-utilities} 4 | \alias{avbase-utilities} 5 | \alias{avstop_for_status} 6 | \alias{avworkspaces_clean} 7 | \title{Helper functions for working in AnVIL} 8 | \usage{ 9 | avstop_for_status(response, op) 10 | 11 | avworkspaces_clean(.data) 12 | } 13 | \arguments{ 14 | \item{response}{Response object from httr} 15 | 16 | \item{op}{Operation that was attempted} 17 | 18 | \item{.data}{A tibble with workspace information} 19 | } 20 | \value{ 21 | \code{avstop_for_status} - \code{response} if status code less than 400 22 | otherwise throw an error 23 | 24 | \code{avworkspaces_clean} - A cleaned tibble with workspace information 25 | } 26 | \description{ 27 | \itemize{ 28 | \item \code{avstop_for_status} - Check HTTP status code and raise error when 29 | less than 400. 30 | } 31 | 32 | \itemize{ 33 | \item \code{avworkspaces_clean} - Clean workspace information 34 | } 35 | } 36 | \examples{ 37 | if (interactive()) { 38 | test <- httr::GET("http://google.com/") 39 | avstop_for_status(test, "google") 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/avworkspace-generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avworkspace-generics.R 3 | \name{avworkspace-generics} 4 | \alias{avworkspace-generics} 5 | \alias{avworkspaces} 6 | \alias{avworkspace_namespace} 7 | \alias{avworkspace_name} 8 | \alias{avworkspace} 9 | \alias{avworkspace_clone} 10 | \title{All the table type generics for AnVIL} 11 | \usage{ 12 | avworkspace(..., platform) 13 | 14 | avworkspaces(..., platform) 15 | 16 | avworkspace_name(..., platform) 17 | 18 | avworkspace_namespace(..., platform) 19 | 20 | avworkspace_clone(..., platform) 21 | } 22 | \arguments{ 23 | \item{...}{Arguments passed to the methods.} 24 | 25 | \item{platform}{A Platform derived class indicating the AnVIL environment, 26 | currently, \code{azure} and \code{gcp} classes are compatible.} 27 | } 28 | \value{ 29 | called for the side effect of registering generic functions 30 | } 31 | \description{ 32 | These are the generics to be used by the AnVIL package. 33 | } 34 | \examples{ 35 | getGeneric("avworkspace") 36 | 37 | } 38 | \seealso{ 39 | \link{AnVILBase-generics}, \link{avtable-generics}, \link{avworkflow-generics} 40 | } 41 | -------------------------------------------------------------------------------- /R/avworkflow-methods.R: -------------------------------------------------------------------------------- 1 | #' @name avworkflow-methods 2 | #' 3 | #' @title All the workflow type methods for AnVIL 4 | #' 5 | #' @description These are the methods to be used by the AnVIL package. 6 | #' 7 | #' @inheritParams avworkflow-generics 8 | #' 9 | #' @include avworkflow-generics.R 10 | #' 11 | #' @return Methods for the 'missing' and 'ANY' signatures provide a way to 12 | #' redirect calls to the appropriate method for the current cloud platform. 13 | #' 14 | #' @examples 15 | #' findMethods("avworkflow_jobs") 16 | #' getMethod("avworkflow_jobs", c(platform = "missing")) 17 | #' 18 | NULL 19 | 20 | #' @describeIn avworkflow-methods Get the status of a workflow execution 21 | #' @exportMethod avworkflow_jobs 22 | setMethod("avworkflow_jobs", c(platform = "missing"), 23 | function(..., platform) { 24 | avworkflow_jobs(..., platform = cloud_platform()) 25 | } 26 | ) 27 | 28 | #' @describeIn avworkflow-methods Get the status of a workflow execution 29 | #' @exportMethod avworkflow_jobs 30 | setMethod("avworkflow_jobs", c(platform = "ANY"), 31 | function(..., platform) { 32 | stop("'avworkflow_jobs()' not implemented for class ", class(platform)) 33 | } 34 | ) 35 | -------------------------------------------------------------------------------- /man/avtable-generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avtable-generics.R 3 | \name{avtable-generics} 4 | \alias{avtable-generics} 5 | \alias{avtable} 6 | \alias{avtables} 7 | \alias{avtable_import} 8 | \alias{avtable_import_set} 9 | \alias{avtable_delete_values} 10 | \alias{avtable_delete} 11 | \title{All the table type generics for AnVIL} 12 | \usage{ 13 | avtable(..., platform) 14 | 15 | avtables(..., platform) 16 | 17 | avtable_import(..., platform) 18 | 19 | avtable_import_set(..., platform) 20 | 21 | avtable_delete(..., platform) 22 | 23 | avtable_delete_values(..., platform) 24 | } 25 | \arguments{ 26 | \item{...}{Arguments passed to the methods.} 27 | 28 | \item{platform}{A Platform derived class indicating the AnVIL environment, 29 | currently, \code{azure} and \code{gcp} classes are compatible.} 30 | } 31 | \value{ 32 | called for the side effect of registering generic functions 33 | } 34 | \description{ 35 | These are the generics to be used by the AnVIL package. 36 | } 37 | \examples{ 38 | getGeneric("avtable") 39 | 40 | } 41 | \seealso{ 42 | \link{AnVILBase-generics}, \link{avworkspace-generics}, \link{avworkflow-generics} 43 | } 44 | -------------------------------------------------------------------------------- /man/avworkflow-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avworkflow-methods.R 3 | \name{avworkflow-methods} 4 | \alias{avworkflow-methods} 5 | \alias{avworkflow_jobs,missing-method} 6 | \alias{avworkflow_jobs,ANY-method} 7 | \title{All the workflow type methods for AnVIL} 8 | \usage{ 9 | \S4method{avworkflow_jobs}{missing}(..., platform) 10 | 11 | \S4method{avworkflow_jobs}{ANY}(..., platform) 12 | } 13 | \arguments{ 14 | \item{...}{Arguments passed to the methods.} 15 | 16 | \item{platform}{A Platform derived class indicating the AnVIL environment, 17 | currently, \code{azure} and \code{gcp} classes are compatible.} 18 | } 19 | \value{ 20 | Methods for the 'missing' and 'ANY' signatures provide a way to 21 | redirect calls to the appropriate method for the current cloud platform. 22 | } 23 | \description{ 24 | These are the methods to be used by the AnVIL package. 25 | } 26 | \section{Functions}{ 27 | \itemize{ 28 | \item \code{avworkflow_jobs(missing)}: Get the status of a workflow execution 29 | 30 | \item \code{avworkflow_jobs(ANY)}: Get the status of a workflow execution 31 | 32 | }} 33 | \examples{ 34 | findMethods("avworkflow_jobs") 35 | getMethod("avworkflow_jobs", c(platform = "missing")) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /R/has_avworkspace-methods.R: -------------------------------------------------------------------------------- 1 | #' @name has_avworkspace-methods 2 | #' 3 | #' @title The `has_avworkspace` methods for `missing` and `ANY` signatures. 4 | #' 5 | #' @description The `AnVILBase` package defines S4 methods for the AnVIL 6 | #' package. These methods are defined for the 'missing' and 'ANY' signatures. 7 | #' 8 | #' @return Methods for the 'missing' and 'ANY' signatures provide a way to 9 | #' redirect calls to the appropriate method for the current cloud platform. 10 | #' 11 | #' @inheritParams has_avworkspace-generics 12 | #' 13 | #' @examples 14 | #' findMethods("has_avworkspace") 15 | #' getMethod("has_avworkspace", c(platform = "missing")) 16 | #' 17 | NULL 18 | 19 | #' @describeIn has_avworkspace-methods Check whether the current 20 | #' workspace is using either Azure or Google infrastructure. 21 | #' 22 | #' @exportMethod has_avworkspace 23 | setMethod("has_avworkspace", c(platform = "missing"), 24 | function(strict, ..., platform) { 25 | has_avworkspace(strict, ..., platform = cloud_platform()) 26 | } 27 | ) 28 | 29 | #' @describeIn has_avworkspace-methods Check whether the current 30 | #' workspace is using either Azure or Google infrastructure. 31 | #' 32 | #' @exportMethod has_avworkspace 33 | setMethod("has_avworkspace", c(platform = "ANY"), 34 | function(strict, ..., platform) { 35 | stop("'has_avworkspace()' not implemented for class ", class(platform)) 36 | } 37 | ) 38 | 39 | -------------------------------------------------------------------------------- /R/avnotebooks-generics.R: -------------------------------------------------------------------------------- 1 | #' @name avnotebooks-generics 2 | #' 3 | #' @aliases avnotebooks avnotebooks_localize avnotebooks_delocalize 4 | #' 5 | #' @title All the avnotebooks generics for AnVIL 6 | #' 7 | #' @description These are the generics to be used by the AnVIL package. 8 | #' 9 | #' @inheritParams AnVILBase-generics 10 | #' 11 | #' @seealso [AnVILBase-generics], [avworkspace-generics], [avtable-generics], 12 | #' [avworkflow-generics] 13 | #' 14 | #' @return called for the side effect of registering generic functions 15 | #' 16 | #' @examples 17 | #' getGeneric("avnotebooks") 18 | #' 19 | #' 20 | NULL 21 | 22 | # avnotebooks -------------------------------------------------------------- 23 | 24 | #' @rdname avnotebooks-generics 25 | #' @export 26 | setGeneric( 27 | "avnotebooks", 28 | function(..., platform) standardGeneric("avnotebooks"), 29 | signature = "platform" 30 | ) 31 | 32 | # avnotebooks_localize ----------------------------------------------------- 33 | 34 | #' @rdname avnotebooks-generics 35 | #' @export 36 | setGeneric( 37 | "avnotebooks_localize", 38 | function(..., platform) standardGeneric("avnotebooks_localize"), 39 | signature = "platform" 40 | ) 41 | 42 | # avnotebooks_delocalize --------------------------------------------------- 43 | 44 | #' @rdname avnotebooks-generics 45 | #' @export 46 | setGeneric( 47 | "avnotebooks_delocalize", 48 | function(..., platform) standardGeneric("avnotebooks_delocalize"), 49 | signature = "platform" 50 | ) 51 | -------------------------------------------------------------------------------- /R/avworkspace-generics.R: -------------------------------------------------------------------------------- 1 | #' @name avworkspace-generics 2 | #' 3 | #' @aliases avworkspaces avworkspace_namespace avworkspace_name avworkspace 4 | #' 5 | #' @title All the table type generics for AnVIL 6 | #' 7 | #' @description These are the generics to be used by the AnVIL package. 8 | #' 9 | #' @inheritParams AnVILBase-generics 10 | #' 11 | #' @seealso [AnVILBase-generics], [avtable-generics], [avworkflow-generics] 12 | #' 13 | #' @return called for the side effect of registering generic functions 14 | #' 15 | #' @examples 16 | #' getGeneric("avworkspace") 17 | #' 18 | NULL 19 | 20 | #' @rdname avworkspace-generics 21 | #' @export 22 | setGeneric( 23 | "avworkspace", 24 | function(..., platform) standardGeneric("avworkspace"), 25 | signature = "platform" 26 | ) 27 | 28 | #' @rdname avworkspace-generics 29 | #' @export 30 | setGeneric( 31 | "avworkspaces", 32 | function(..., platform) standardGeneric("avworkspaces"), 33 | signature = "platform" 34 | ) 35 | 36 | #' @rdname avworkspace-generics 37 | #' @export 38 | setGeneric( 39 | "avworkspace_name", 40 | function(..., platform) standardGeneric("avworkspace_name"), 41 | signature = "platform" 42 | ) 43 | 44 | #' @rdname avworkspace-generics 45 | #' @export 46 | setGeneric( 47 | "avworkspace_namespace", 48 | function(..., platform) standardGeneric("avworkspace_namespace"), 49 | signature = "platform" 50 | ) 51 | 52 | #' @rdname avworkspace-generics 53 | #' @export 54 | setGeneric( 55 | "avworkspace_clone", 56 | function(..., platform) standardGeneric("avworkspace_clone"), 57 | signature = "platform" 58 | ) 59 | -------------------------------------------------------------------------------- /man/has_avworkspace-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/has_avworkspace-methods.R 3 | \name{has_avworkspace-methods} 4 | \alias{has_avworkspace-methods} 5 | \alias{has_avworkspace,missing-method} 6 | \alias{has_avworkspace,ANY-method} 7 | \title{The \code{has_avworkspace} methods for \code{missing} and \code{ANY} signatures.} 8 | \usage{ 9 | \S4method{has_avworkspace}{missing}(strict = FALSE, ..., platform) 10 | 11 | \S4method{has_avworkspace}{ANY}(strict = FALSE, ..., platform) 12 | } 13 | \arguments{ 14 | \item{strict}{\code{logical(1)} Whether to include a check for an existing 15 | \code{avworkspace_name()} setting. Default \code{FALSE}.} 16 | 17 | \item{...}{Arguments passed to the methods.} 18 | 19 | \item{platform}{A Platform derived class indicating the AnVIL environment, 20 | currently, \code{azure} and \code{gcp} classes are compatible.} 21 | } 22 | \value{ 23 | Methods for the 'missing' and 'ANY' signatures provide a way to 24 | redirect calls to the appropriate method for the current cloud platform. 25 | } 26 | \description{ 27 | The \code{AnVILBase} package defines S4 methods for the AnVIL 28 | package. These methods are defined for the 'missing' and 'ANY' signatures. 29 | } 30 | \section{Functions}{ 31 | \itemize{ 32 | \item \code{has_avworkspace(missing)}: Check whether the current 33 | workspace is using either Azure or Google infrastructure. 34 | 35 | \item \code{has_avworkspace(ANY)}: Check whether the current 36 | workspace is using either Azure or Google infrastructure. 37 | 38 | }} 39 | \examples{ 40 | findMethods("has_avworkspace") 41 | getMethod("has_avworkspace", c(platform = "missing")) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /R/AnVILBase-generics.R: -------------------------------------------------------------------------------- 1 | #' @name AnVILBase-generics 2 | #' 3 | #' @aliases avcopy avlist avremove avbackup avrestore avstorage 4 | #' 5 | #' @title All the generics for AnVIL 6 | #' 7 | #' @description These are the generics to be used by the AnVIL package. 8 | #' 9 | #' @param platform A Platform derived class indicating the AnVIL environment, 10 | #' currently, `azure` and `gcp` classes are compatible. 11 | #' 12 | #' @param ... Arguments passed to the methods. 13 | #' 14 | #' @seealso [avworkspace-generics], [avtable-generics], [avworkflow-generics] 15 | #' 16 | #' @return called for the side effect of registering generic functions 17 | #' 18 | #' @examples 19 | #' getGeneric("avcopy") 20 | #' 21 | #' @export 22 | setGeneric( 23 | "avcopy", 24 | function(..., platform) standardGeneric("avcopy"), 25 | signature = "platform" 26 | ) 27 | 28 | #' @rdname AnVILBase-generics 29 | #' @export 30 | setGeneric( 31 | "avlist", 32 | function(..., platform) standardGeneric("avlist"), 33 | signature = "platform" 34 | ) 35 | 36 | #' @rdname AnVILBase-generics 37 | #' @export 38 | setGeneric( 39 | "avremove", 40 | function(..., platform) standardGeneric("avremove"), 41 | signature = "platform" 42 | ) 43 | 44 | #' @rdname AnVILBase-generics 45 | #' @export 46 | setGeneric( 47 | "avbackup", 48 | function(..., platform) standardGeneric("avbackup"), 49 | signature = "platform" 50 | ) 51 | 52 | #' @rdname AnVILBase-generics 53 | #' @export 54 | setGeneric( 55 | "avrestore", 56 | function(..., platform) standardGeneric("avrestore"), 57 | signature = "platform" 58 | ) 59 | 60 | #' @rdname AnVILBase-generics 61 | #' @export 62 | setGeneric( 63 | "avstorage", 64 | function(..., platform) standardGeneric("avstorage"), 65 | signature = "platform" 66 | ) 67 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: AnVILBase 2 | Title: Generic functions for interacting with the AnVIL ecosystem 3 | Version: 1.5.1 4 | Authors@R: c( 5 | person("Marcel", "Ramos", , "marcel.ramos@sph.cuny.edu", 6 | c("aut", "cre"), c(ORCID = "0000-0002-3242-0582")), 7 | person("Martin", "Morgan", , , c("aut", "ctb"), 8 | c(ORCID = "0000-0002-5874-8148")), 9 | person("NIH NHGRI U24HG004059", role = "fnd") 10 | ) 11 | Description: Provides generic functions for interacting with the AnVIL 12 | ecosystem. Packages that use either GCP or Azure in AnVIL are built on top 13 | of AnVILBase. Extension packages will provide methods for interacting with 14 | other cloud providers. 15 | License: Artistic-2.0 16 | Depends: R (>= 4.5.0) 17 | Imports: 18 | httr, 19 | httr2, 20 | dplyr, 21 | jsonlite, 22 | methods, 23 | tibble 24 | Suggests: 25 | AnVIL, 26 | AnVILAz, 27 | AnVILGCP, 28 | BiocStyle, 29 | GCPtools, 30 | knitr, 31 | rmarkdown, 32 | testthat (>= 3.0.0), 33 | tinytest 34 | biocViews: Software, Infrastructure 35 | URL: https://github.com/Bioconductor/AnVILBase 36 | BugReports: https://github.com/Bioconductor/AnVILBase/issues 37 | VignetteBuilder: knitr 38 | Encoding: UTF-8 39 | Roxygen: list(markdown = TRUE) 40 | RoxygenNote: 7.3.3 41 | Date: 2025-11-10 42 | Config/testthat/edition: 3 43 | Collate: 44 | 'AnVILBase-generics.R' 45 | 'AnVILBase-methods.R' 46 | 'AnVILBase-package.R' 47 | 'Platform-class.R' 48 | 'Response.R' 49 | 'avnotebooks-generics.R' 50 | 'avnotebooks-methods.R' 51 | 'avtable-generics.R' 52 | 'avtable-methods.R' 53 | 'avworkflow-generics.R' 54 | 'avworkflow-methods.R' 55 | 'avworkspace-generics.R' 56 | 'avworkspace-methods.R' 57 | 'cloud_platform.R' 58 | 'has_avworkspace-generics.R' 59 | 'has_avworkspace-methods.R' 60 | 'utilities.R' 61 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(as.list,response) 4 | export(avbackup) 5 | export(avcopy) 6 | export(avlist) 7 | export(avnotebooks) 8 | export(avnotebooks_delocalize) 9 | export(avnotebooks_localize) 10 | export(avplatform_namespace) 11 | export(avremove) 12 | export(avrestore) 13 | export(avstop_for_status) 14 | export(avstorage) 15 | export(avtable) 16 | export(avtable_delete) 17 | export(avtable_delete_values) 18 | export(avtable_import) 19 | export(avtable_import_set) 20 | export(avtables) 21 | export(avworkflow_jobs) 22 | export(avworkspace) 23 | export(avworkspace_clone) 24 | export(avworkspace_name) 25 | export(avworkspace_namespace) 26 | export(avworkspaces) 27 | export(avworkspaces_clean) 28 | export(cloud_platform) 29 | export(flatten) 30 | export(has_avworkspace) 31 | exportClasses(Platform) 32 | exportMethods(avbackup) 33 | exportMethods(avcopy) 34 | exportMethods(avlist) 35 | exportMethods(avnotebooks) 36 | exportMethods(avnotebooks_delocalize) 37 | exportMethods(avnotebooks_localize) 38 | exportMethods(avremove) 39 | exportMethods(avrestore) 40 | exportMethods(avstorage) 41 | exportMethods(avtable) 42 | exportMethods(avtable_delete) 43 | exportMethods(avtable_delete_values) 44 | exportMethods(avtable_import) 45 | exportMethods(avtable_import_set) 46 | exportMethods(avtables) 47 | exportMethods(avworkflow_jobs) 48 | exportMethods(avworkspace) 49 | exportMethods(avworkspace_clone) 50 | exportMethods(avworkspace_name) 51 | exportMethods(avworkspace_namespace) 52 | exportMethods(avworkspaces) 53 | exportMethods(flatten) 54 | exportMethods(has_avworkspace) 55 | exportMethods(str) 56 | import(methods) 57 | importFrom(httr,content) 58 | importFrom(httr,headers) 59 | importFrom(httr,http_condition) 60 | importFrom(httr,status_code) 61 | importFrom(httr2,resp_body_string) 62 | importFrom(jsonlite,fromJSON) 63 | importFrom(tibble,as_tibble) 64 | -------------------------------------------------------------------------------- /man/Response.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Response.R 3 | \name{Response} 4 | \alias{Response} 5 | \alias{flatten,response-method} 6 | \alias{flatten} 7 | \alias{str,response-method} 8 | \alias{as.list.response} 9 | \alias{flatten,httr2_response-method} 10 | \title{Process service responses to tibble and other data structures.} 11 | \usage{ 12 | flatten(x) 13 | 14 | \S4method{flatten}{response}(x) 15 | 16 | \S4method{str}{response}(object) 17 | 18 | \method{as.list}{response}(x, ..., as = c("text", "raw", "parsed")) 19 | 20 | \S4method{flatten}{httr2_response}(x) 21 | } 22 | \arguments{ 23 | \item{x}{A \code{response} object returned by the service.} 24 | 25 | \item{object}{A \code{response} object returned by the service.} 26 | 27 | \item{\dots}{not currently used} 28 | 29 | \item{as}{character(1); one of 'raw', 'text', 'parsed'} 30 | } 31 | \value{ 32 | \code{flatten()} returns a \code{tibble} where each row correseponds 33 | to a top-level list element of the return value, and columns 34 | are the unlisted second and more-nested elements. 35 | 36 | \code{str()} displays a compact representation of the list-like 37 | JSON response; it returns \code{NULL}. 38 | 39 | \code{as.list()} returns the content of the web service request 40 | as a list. 41 | } 42 | \description{ 43 | Process service responses to tibble and other data structures. 44 | } 45 | \section{Functions}{ 46 | \itemize{ 47 | \item \code{flatten(response)}: Reduce httr response object to a two-dimensional table 48 | 49 | \item \code{str(response)}: Create a compact representation of the list-like JSON 50 | response 51 | 52 | \item \code{flatten(httr2_response)}: Reduce httr2 request responses to two-dimensional table 53 | form 54 | 55 | }} 56 | \examples{ 57 | if (GCPtools::gcloud_exists() && interactive()) { 58 | library(AnVIL) 59 | leonardo <- Leonardo() 60 | leonardo$listRuntimes() |> flatten() 61 | 62 | leonardo$getSystemStatus() |> str() 63 | 64 | leonardo$getSystemStatus() |> as.list() 65 | } 66 | } 67 | \author{ 68 | M. Morgan, M. Ramos 69 | } 70 | -------------------------------------------------------------------------------- /R/avtable-generics.R: -------------------------------------------------------------------------------- 1 | #' @name avtable-generics 2 | #' 3 | #' @aliases avtable avtables avtable_import avtable_import_set 4 | #' avtable_delete_values 5 | #' 6 | #' @title All the table type generics for AnVIL 7 | #' 8 | #' @description These are the generics to be used by the AnVIL package. 9 | #' 10 | #' @inheritParams AnVILBase-generics 11 | #' 12 | #' @seealso [AnVILBase-generics], [avworkspace-generics], [avworkflow-generics] 13 | #' 14 | #' @return called for the side effect of registering generic functions 15 | #' 16 | #' @examples 17 | #' getGeneric("avtable") 18 | #' 19 | NULL 20 | 21 | # avtable ----------------------------------------------------------------- 22 | 23 | #' @rdname avtable-generics 24 | #' @export 25 | setGeneric( 26 | "avtable", 27 | function(..., platform) standardGeneric("avtable"), 28 | signature = "platform" 29 | ) 30 | 31 | # avtables ---------------------------------------------------------------- 32 | 33 | #' @rdname avtable-generics 34 | #' @export 35 | setGeneric( 36 | "avtables", 37 | function(..., platform) standardGeneric("avtables"), 38 | signature = "platform" 39 | ) 40 | 41 | # avtable_import ---------------------------------------------------------- 42 | 43 | #' @rdname avtable-generics 44 | #' @export 45 | setGeneric( 46 | "avtable_import", 47 | function(..., platform) standardGeneric("avtable_import"), 48 | signature = "platform" 49 | ) 50 | #' @rdname avtable-generics 51 | #' @export 52 | setGeneric( 53 | "avtable_import_set", 54 | function(..., platform) standardGeneric("avtable_import_set"), 55 | signature = "platform" 56 | ) 57 | 58 | # avtable_import_set ------------------------------------------------------ 59 | 60 | #' @rdname avtable-generics 61 | #' @export 62 | setGeneric( 63 | "avtable_delete", 64 | function(..., platform) standardGeneric("avtable_delete"), 65 | signature = "platform" 66 | ) 67 | 68 | # avtable_delete_values --------------------------------------------------- 69 | 70 | #' @rdname avtable-generics 71 | #' @export 72 | setGeneric( 73 | "avtable_delete_values", 74 | function(..., platform) standardGeneric("avtable_delete_values"), 75 | signature = "platform" 76 | ) 77 | -------------------------------------------------------------------------------- /man/avnotebooks-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avnotebooks-methods.R 3 | \name{avnotebooks-methods} 4 | \alias{avnotebooks-methods} 5 | \alias{avnotebooks,missing-method} 6 | \alias{avnotebooks,ANY-method} 7 | \alias{avnotebooks_localize,missing-method} 8 | \alias{avnotebooks_localize,ANY-method} 9 | \alias{avnotebooks_delocalize,missing-method} 10 | \alias{avnotebooks_delocalize,ANY-method} 11 | \title{All the notebook type methods for AnVIL} 12 | \usage{ 13 | \S4method{avnotebooks}{missing}(..., platform) 14 | 15 | \S4method{avnotebooks}{ANY}(..., platform) 16 | 17 | \S4method{avnotebooks_localize}{missing}(..., platform) 18 | 19 | \S4method{avnotebooks_localize}{ANY}(..., platform) 20 | 21 | \S4method{avnotebooks_delocalize}{missing}(..., platform) 22 | 23 | \S4method{avnotebooks_delocalize}{ANY}(..., platform) 24 | } 25 | \arguments{ 26 | \item{...}{Arguments passed to the methods.} 27 | 28 | \item{platform}{A Platform derived class indicating the AnVIL environment, 29 | currently, \code{azure} and \code{gcp} classes are compatible.} 30 | } 31 | \value{ 32 | Methods for the 'missing' and 'ANY' signatures provide a way to 33 | redirect calls to the appropriate method for the current cloud platform. 34 | } 35 | \description{ 36 | These are the methods to be used by the AnVIL package. 37 | } 38 | \section{Functions}{ 39 | \itemize{ 40 | \item \code{avnotebooks(missing)}: List the available notebooks in the current 41 | workspace 42 | 43 | \item \code{avnotebooks(ANY)}: List the available notebooks in the current 44 | workspace 45 | 46 | \item \code{avnotebooks_localize(missing)}: sync the contents of the workspace storage to 47 | the local file system 48 | 49 | \item \code{avnotebooks_localize(ANY)}: sync the contents of the workspace storage to 50 | the local file system 51 | 52 | \item \code{avnotebooks_delocalize(missing)}: sync the contents of the local file system to 53 | the workspace storage 54 | 55 | \item \code{avnotebooks_delocalize(ANY)}: sync the contents of the local file system to 56 | the workspace storage 57 | 58 | }} 59 | \examples{ 60 | findMethods("avnotebooks") 61 | getMethod("avnotebooks", c(platform = "missing")) 62 | 63 | } 64 | -------------------------------------------------------------------------------- /man/cloud_platform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cloud_platform.R 3 | \name{cloud_platform} 4 | \alias{cloud_platform} 5 | \alias{avplatform_namespace} 6 | \title{Cloud Platform Identifier} 7 | \usage{ 8 | avplatform_namespace(default = "") 9 | 10 | cloud_platform() 11 | } 12 | \arguments{ 13 | \item{default}{\code{character(1)}. The default cloud platform to use if no 14 | environment variables or options are set. The default is \code{""}.} 15 | } 16 | \value{ 17 | For \code{avplatform_namespace}: A character string indicating the cloud 18 | platform derived from environment variables. 19 | 20 | For \code{cloud_platform}: An instance of class \code{gcp} or \code{azure} based on 21 | environment variables or options set within the AnVIL workspace. For 22 | \code{avplatform_namespace}: A character string indicating the cloud platform. 23 | } 24 | \description{ 25 | \code{cloud_platform} calls the appropriate class constructor based 26 | on environment variables or options within the workspace. This function is 27 | used to determine the cloud platform to dispatch on for AnVIL methods. It 28 | returns an error when neither the Azure or Google Cloud environment 29 | variables are set. The \code{avplatform_namespace} function is a lower level 30 | helper to identify the platform based on environment variables or options. 31 | Generally, these functions are \emph{not} meant to be used directly. 32 | } 33 | \details{ 34 | When \code{GOOGLE_PROJECT} is set, the function returns an object of 35 | class \code{gcp}. When \code{WORKSPACE_ID} is set, the function returns an object of 36 | class \code{azure}. Otherwise, the function returns an error. The user may also 37 | add options to set a default cloud platform. For AnVIL instances running on 38 | Google Cloud, the user can set 39 | \code{options(GCLOUD_SDK_PATH = "/home/user/google-cloud-sdk")} 40 | to set the default cloud platform to \code{gcp}. For AnVIL instances running on 41 | Azure, the user can set \code{options(AnVILAz.workspace_id = "myworkspace")} 42 | to set the default cloud platform to \code{azure}. Note that the values provided 43 | are example values and should be replaced with verifiable values. 44 | } 45 | \examples{ 46 | avplatform_namespace() 47 | if (interactive()) { 48 | cloud_platform() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /R/utilities.R: -------------------------------------------------------------------------------- 1 | #' @name avbase-utilities 2 | #' 3 | #' @title Helper functions for working in AnVIL 4 | #' 5 | #' @description 6 | #' * `avstop_for_status` - Check HTTP status code and raise error when 7 | #' less than 400. 8 | #' 9 | #' @param response Response object from httr 10 | #' 11 | #' @param op Operation that was attempted 12 | #' 13 | #' @importFrom httr status_code http_condition headers 14 | #' 15 | #' @return `avstop_for_status` - `response` if status code less than 400 16 | #' otherwise throw an error 17 | #' 18 | #' @examples 19 | #' if (interactive()) { 20 | #' test <- httr::GET("http://google.com/") 21 | #' avstop_for_status(test, "google") 22 | #' } 23 | #' 24 | #' @export 25 | avstop_for_status <- 26 | function(response, op) 27 | { 28 | status <- status_code(response) 29 | if (status < 400L) 30 | return(invisible(response)) 31 | 32 | cond <- http_condition(status, "error") 33 | type <- headers(response)[["content-type"]] 34 | msg <- NULL 35 | if (nzchar(type) && grepl("application/json", type)) { 36 | content <- as.list(response) 37 | msg <- content[["message"]] 38 | if (is.null(msg)) 39 | ## e.g., from bond DRS server 40 | msg <- content$response$text 41 | } else if (nzchar(type) && grepl("text/html", type)) { 42 | ## these pages can be too long for a standard 'stop()' message 43 | cat(as.character(response), file = stderr()) 44 | } 45 | 46 | message <- paste0( 47 | "'", op, "' failed:\n ", 48 | conditionMessage(cond), 49 | if (!is.null(msg)) "\n ", msg 50 | ) 51 | stop(message, call.=FALSE) 52 | } 53 | 54 | #' @rdname avbase-utilities 55 | #' 56 | #' @description 57 | #' * `avworkspaces_clean` - Clean workspace information 58 | #' 59 | #' @param .data A tibble with workspace information 60 | #' 61 | #' @return `avworkspaces_clean` - A cleaned tibble with workspace information 62 | #' 63 | #' @export 64 | avworkspaces_clean <- function(.data) { 65 | .data |> 66 | dplyr::select( 67 | name = .data$workspace.name, 68 | lastModified = .data$workspace.lastModified, 69 | createdBy = .data$workspace.createdBy, 70 | namespace = .data$workspace.namespace, 71 | accessLevel = .data$accessLevel 72 | ) |> 73 | dplyr::mutate( 74 | lastModified = as.Date(.data$lastModified) 75 | ) |> 76 | dplyr::arrange( 77 | .data$name, 78 | dplyr::desc(.data$lastModified) 79 | ) 80 | } 81 | -------------------------------------------------------------------------------- /R/avnotebooks-methods.R: -------------------------------------------------------------------------------- 1 | #' @name avnotebooks-methods 2 | #' 3 | #' @title All the notebook type methods for AnVIL 4 | #' 5 | #' @description These are the methods to be used by the AnVIL package. 6 | #' 7 | #' @inheritParams avnotebooks-generics 8 | #' 9 | #' @include avnotebooks-generics.R 10 | #' 11 | #' @return Methods for the 'missing' and 'ANY' signatures provide a way to 12 | #' redirect calls to the appropriate method for the current cloud platform. 13 | #' 14 | #' @examples 15 | #' findMethods("avnotebooks") 16 | #' getMethod("avnotebooks", c(platform = "missing")) 17 | #' 18 | NULL 19 | 20 | #' @describeIn avnotebooks-methods List the available notebooks in the current 21 | #' workspace 22 | #' 23 | #' @exportMethod avnotebooks 24 | setMethod("avnotebooks", c(platform = "missing"), 25 | function(..., platform) { 26 | avnotebooks(..., platform = cloud_platform()) 27 | } 28 | ) 29 | 30 | #' @describeIn avnotebooks-methods List the available notebooks in the current 31 | #' workspace 32 | #' 33 | #' @exportMethod avnotebooks 34 | setMethod("avnotebooks", c(platform = "ANY"), 35 | function(..., platform) { 36 | stop("'avnotebooks()' not implemented for class ", class(platform)) 37 | } 38 | ) 39 | 40 | #' @describeIn avnotebooks-methods sync the contents of the workspace storage to 41 | #' the local file system 42 | #' 43 | #' @exportMethod avnotebooks_localize 44 | setMethod("avnotebooks_localize", c(platform = "missing"), 45 | function(..., platform) { 46 | avnotebooks_localize(..., platform = cloud_platform()) 47 | } 48 | ) 49 | 50 | #' @describeIn avnotebooks-methods sync the contents of the workspace storage to 51 | #' the local file system 52 | #' 53 | #' @exportMethod avnotebooks_localize 54 | setMethod("avnotebooks_localize", c(platform = "ANY"), 55 | function(..., platform) { 56 | stop( 57 | "'avnotebooks_localize()' not implemented for class ", 58 | class(platform) 59 | ) 60 | } 61 | ) 62 | 63 | #' @describeIn avnotebooks-methods sync the contents of the local file system to 64 | #' the workspace storage 65 | #' 66 | #' @exportMethod avnotebooks_delocalize 67 | setMethod("avnotebooks_delocalize", c(platform = "missing"), 68 | function(..., platform) { 69 | avnotebooks_delocalize(..., platform = cloud_platform()) 70 | } 71 | ) 72 | 73 | #' @describeIn avnotebooks-methods sync the contents of the local file system to 74 | #' the workspace storage 75 | #' 76 | #' @exportMethod avnotebooks_delocalize 77 | setMethod("avnotebooks_delocalize", c(platform = "ANY"), 78 | function(..., platform) { 79 | stop( 80 | "'avnotebooks_delocalize()' not implemented for class ", 81 | class(platform) 82 | ) 83 | } 84 | ) 85 | -------------------------------------------------------------------------------- /man/AnVILBase-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AnVILBase-methods.R 3 | \name{AnVILBase-methods} 4 | \alias{AnVILBase-methods} 5 | \alias{avcopy,missing-method} 6 | \alias{avcopy,ANY-method} 7 | \alias{avlist,missing-method} 8 | \alias{avlist,ANY-method} 9 | \alias{avremove,missing-method} 10 | \alias{avremove,ANY-method} 11 | \alias{avbackup,missing-method} 12 | \alias{avbackup,ANY-method} 13 | \alias{avrestore,missing-method} 14 | \alias{avrestore,ANY-method} 15 | \alias{avstorage,missing-method} 16 | \alias{avstorage,ANY-method} 17 | \title{The AnVILBase methods for 'missing' and 'ANY' signatures} 18 | \usage{ 19 | \S4method{avcopy}{missing}(..., platform) 20 | 21 | \S4method{avcopy}{ANY}(..., platform) 22 | 23 | \S4method{avlist}{missing}(..., platform) 24 | 25 | \S4method{avlist}{ANY}(..., platform) 26 | 27 | \S4method{avremove}{missing}(..., platform) 28 | 29 | \S4method{avremove}{ANY}(..., platform) 30 | 31 | \S4method{avbackup}{missing}(..., platform) 32 | 33 | \S4method{avbackup}{ANY}(..., platform) 34 | 35 | \S4method{avrestore}{missing}(..., platform) 36 | 37 | \S4method{avrestore}{ANY}(..., platform) 38 | 39 | \S4method{avstorage}{missing}(..., platform) 40 | 41 | \S4method{avstorage}{ANY}(..., platform) 42 | } 43 | \arguments{ 44 | \item{...}{Arguments passed to the methods.} 45 | 46 | \item{platform}{A Platform derived class indicating the AnVIL environment, 47 | currently, \code{azure} and \code{gcp} classes are compatible.} 48 | } 49 | \value{ 50 | Methods for the 'missing' and 'ANY' signatures provide a way to 51 | redirect calls to the appropriate method for the current cloud platform. 52 | } 53 | \description{ 54 | The \code{AnVILBase} package defines S4 methods for the AnVIL 55 | package. These methods are defined for the 'missing' and 'ANY' signatures. 56 | } 57 | \section{Functions}{ 58 | \itemize{ 59 | \item \code{avcopy(missing)}: Copy a file from the cloud 60 | 61 | \item \code{avcopy(ANY)}: Copy a file from the cloud 62 | 63 | \item \code{avlist(missing)}: List files in the cloud 64 | 65 | \item \code{avlist(ANY)}: List files in the cloud 66 | 67 | \item \code{avremove(missing)}: Remove a file from the cloud 68 | 69 | \item \code{avremove(ANY)}: Remove a file from the cloud 70 | 71 | \item \code{avbackup(missing)}: Backup a file to the cloud 72 | 73 | \item \code{avbackup(ANY)}: Backup a file to the cloud 74 | 75 | \item \code{avrestore(missing)}: Restore a file from the cloud 76 | 77 | \item \code{avrestore(ANY)}: Restore a file from the cloud 78 | 79 | \item \code{avstorage(missing)}: Get the storage location 80 | 81 | \item \code{avstorage(ANY)}: Get the storage location 82 | 83 | }} 84 | \examples{ 85 | findMethods("avcopy") 86 | getMethod("avcopy", c(platform = "missing")) 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /man/avworkspace-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avworkspace-methods.R 3 | \name{avworkspace-methods} 4 | \alias{avworkspace-methods} 5 | \alias{avworkspace,missing-method} 6 | \alias{avworkspace,ANY-method} 7 | \alias{avworkspaces,missing-method} 8 | \alias{avworkspaces,ANY-method} 9 | \alias{avworkspace_name,missing-method} 10 | \alias{avworkspace_name,ANY-method} 11 | \alias{avworkspace_namespace,missing-method} 12 | \alias{avworkspace_namespace,ANY-method} 13 | \alias{avworkspace_clone,missing-method} 14 | \alias{avworkspace_clone,ANY-method} 15 | \title{The \code{avworkspace} methods for 'missing' and 'ANY' signatures} 16 | \usage{ 17 | \S4method{avworkspace}{missing}(..., platform) 18 | 19 | \S4method{avworkspace}{ANY}(..., platform) 20 | 21 | \S4method{avworkspaces}{missing}(..., platform) 22 | 23 | \S4method{avworkspaces}{ANY}(..., platform) 24 | 25 | \S4method{avworkspace_name}{missing}(..., platform) 26 | 27 | \S4method{avworkspace_name}{ANY}(..., platform) 28 | 29 | \S4method{avworkspace_namespace}{missing}(..., platform) 30 | 31 | \S4method{avworkspace_namespace}{ANY}(..., platform) 32 | 33 | \S4method{avworkspace_clone}{missing}(..., platform) 34 | 35 | \S4method{avworkspace_clone}{ANY}(..., platform) 36 | } 37 | \arguments{ 38 | \item{...}{Arguments passed to the methods.} 39 | 40 | \item{platform}{A Platform derived class indicating the AnVIL environment, 41 | currently, \code{azure} and \code{gcp} classes are compatible.} 42 | } 43 | \value{ 44 | Methods for the 'missing' and 'ANY' signatures provide a way to 45 | redirect calls to the appropriate method for the current cloud platform. 46 | } 47 | \description{ 48 | The \code{AnVILBase} package defines S4 methods for the AnVIL 49 | package. These methods are defined for the 'missing' and 'ANY' signatures. 50 | } 51 | \section{Functions}{ 52 | \itemize{ 53 | \item \code{avworkspace(missing)}: Get the current workspace namespace/name 54 | 55 | \item \code{avworkspace(ANY)}: Get the current workspace namespace/name 56 | 57 | \item \code{avworkspaces(missing)}: List workspaces 58 | 59 | \item \code{avworkspaces(ANY)}: List workspaces 60 | 61 | \item \code{avworkspace_name(missing)}: Get the name of the current workspace 62 | 63 | \item \code{avworkspace_name(ANY)}: Get the name of the current workspace 64 | 65 | \item \code{avworkspace_namespace(missing)}: Get the namespace of the current workspace 66 | 67 | \item \code{avworkspace_namespace(ANY)}: Get the namespace of the current workspace 68 | 69 | \item \code{avworkspace_clone(missing)}: Clone the current workspace 70 | 71 | \item \code{avworkspace_clone(ANY)}: Clone the current workspace 72 | 73 | }} 74 | \examples{ 75 | findMethods("avworkspace") 76 | getMethod("avworkspace", c(platform = "missing")) 77 | 78 | } 79 | -------------------------------------------------------------------------------- /R/Response.R: -------------------------------------------------------------------------------- 1 | setOldClass("response") 2 | setOldClass("httr2_response") 3 | 4 | #' @rdname Response 5 | #' 6 | #' @name Response 7 | #' 8 | #' @aliases flatten,response-method 9 | #' 10 | #' @author M. Morgan, M. Ramos 11 | #' 12 | #' @importFrom httr content 13 | #' @importFrom httr2 resp_body_string 14 | #' @importFrom jsonlite fromJSON 15 | #' @importFrom tibble as_tibble 16 | NULL 17 | 18 | #' @rdname Response 19 | #' 20 | #' @name Response 21 | #' 22 | #' @title Process service responses to tibble and other data structures. 23 | #' 24 | #' @aliases flatten 25 | #' 26 | #' @param x A `response` object returned by the service. 27 | #' 28 | #' @return `flatten()` returns a `tibble` where each row correseponds 29 | #' to a top-level list element of the return value, and columns 30 | #' are the unlisted second and more-nested elements. 31 | #' 32 | #' @examples 33 | #' if (GCPtools::gcloud_exists() && interactive()) { 34 | #' library(AnVIL) 35 | #' leonardo <- Leonardo() 36 | #' leonardo$listRuntimes() |> flatten() 37 | #' 38 | #' leonardo$getSystemStatus() |> str() 39 | #' 40 | #' leonardo$getSystemStatus() |> as.list() 41 | #' } 42 | #' @export 43 | setGeneric("flatten", function(x) standardGeneric("flatten")) 44 | 45 | #' @describeIn Response Reduce httr response object to a two-dimensional table 46 | #' @exportMethod flatten 47 | setMethod("flatten", "response", 48 | function(x) 49 | { 50 | .resp_tibble(x, content, as="text", encoding = "UTF-8") 51 | }) 52 | 53 | #' @describeIn Response Create a compact representation of the list-like JSON 54 | #' response 55 | #' 56 | #' @param object A `response` object returned by the service. 57 | #' 58 | #' @return `str()` displays a compact representation of the list-like 59 | #' JSON response; it returns `NULL`. 60 | #' 61 | #' @exportMethod str 62 | setMethod("str", "response", 63 | function(object) 64 | { 65 | value <- content(object, as="text", encoding = "UTF-8") 66 | if (nzchar(value)) { 67 | json <- fromJSON(value) 68 | } else { 69 | json <- character() 70 | } 71 | str(json) 72 | }) 73 | 74 | #' @rdname Response 75 | #' 76 | #' @param as character(1); one of 'raw', 'text', 'parsed' 77 | #' 78 | #' @param \dots not currently used 79 | #' 80 | #' @return `as.list()` returns the content of the web service request 81 | #' as a list. 82 | #' 83 | #' @export 84 | as.list.response <- 85 | function(x, ..., as=c("text", "raw", "parsed")) 86 | { 87 | as <- match.arg(as) 88 | value <- content(x, as=as, encoding = "UTF-8") 89 | if (identical(as, "text") && nzchar(value)) { 90 | value <- fromJSON(value) 91 | } 92 | value 93 | } 94 | 95 | #' @describeIn Response Reduce httr2 request responses to two-dimensional table 96 | #' form 97 | #' @exportMethod flatten 98 | setMethod("flatten", "httr2_response", 99 | function(x) 100 | { 101 | .resp_tibble(x, httr2::resp_body_string) 102 | }) 103 | 104 | .resp_tibble <- function(x, fun, ...) { 105 | value <- fun(x, ...) 106 | if (nzchar(value)) { 107 | json <- fromJSON(value, flatten = TRUE) 108 | tibble::as_tibble(json) 109 | } else { 110 | tibble::tibble() 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /man/avtable-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/avtable-methods.R 3 | \name{avtable-methods} 4 | \alias{avtable-methods} 5 | \alias{avtable,missing-method} 6 | \alias{avtable,ANY-method} 7 | \alias{avtables,missing-method} 8 | \alias{avtables,ANY-method} 9 | \alias{avtable_import,missing-method} 10 | \alias{avtable_import,ANY-method} 11 | \alias{avtable_import_set,missing-method} 12 | \alias{avtable_import_set,ANY-method} 13 | \alias{avtable_delete,missing-method} 14 | \alias{avtable_delete,ANY-method} 15 | \alias{avtable_delete_values,missing-method} 16 | \alias{avtable_delete_values,ANY-method} 17 | \title{The avtable methods for 'missing' and 'ANY' signatures} 18 | \usage{ 19 | \S4method{avtable}{missing}(..., platform) 20 | 21 | \S4method{avtable}{ANY}(..., platform) 22 | 23 | \S4method{avtables}{missing}(..., platform) 24 | 25 | \S4method{avtables}{ANY}(..., platform) 26 | 27 | \S4method{avtable_import}{missing}(..., platform) 28 | 29 | \S4method{avtable_import}{ANY}(..., platform) 30 | 31 | \S4method{avtable_import_set}{missing}(..., platform) 32 | 33 | \S4method{avtable_import_set}{ANY}(..., platform) 34 | 35 | \S4method{avtable_delete}{missing}(..., platform) 36 | 37 | \S4method{avtable_delete}{ANY}(..., platform) 38 | 39 | \S4method{avtable_delete_values}{missing}(..., platform) 40 | 41 | \S4method{avtable_delete_values}{ANY}(..., platform) 42 | } 43 | \arguments{ 44 | \item{...}{Arguments passed to the methods.} 45 | 46 | \item{platform}{A Platform derived class indicating the AnVIL environment, 47 | currently, \code{azure} and \code{gcp} classes are compatible.} 48 | } 49 | \value{ 50 | Methods for the 'missing' and 'ANY' signatures provide a way to 51 | redirect calls to the appropriate method for the current cloud platform. 52 | } 53 | \description{ 54 | The \code{AnVILBase} package defines S4 methods for the AnVIL 55 | package. These methods are defined for the 'missing' and 'ANY' signatures. 56 | } 57 | \section{Functions}{ 58 | \itemize{ 59 | \item \code{avtable(missing)}: Show the contents of a particular table (entity 60 | / type) within a workspace. 61 | 62 | \item \code{avtable(ANY)}: Show the contents of a particular table (entity 63 | / type) within a workspace. 64 | 65 | \item \code{avtables(missing)}: List entities / types accross or within 66 | the current workspace respectively. 67 | 68 | \item \code{avtables(ANY)}: List entities / types accross or within 69 | the current workspace respectively. 70 | 71 | \item \code{avtable_import(missing)}: Upload a dataset to the DATA tab 72 | 73 | \item \code{avtable_import(ANY)}: Upload a dataset to the DATA tab 74 | 75 | \item \code{avtable_import_set(missing)}: Creates a grouping table for each 76 | distinct value in the column identified by \code{set}. 77 | 78 | \item \code{avtable_import_set(ANY)}: Creates a grouping table for each 79 | distinct value in the column identified by \code{set}. 80 | 81 | \item \code{avtable_delete(missing)}: Delete a table 82 | 83 | \item \code{avtable_delete(ANY)}: Delete a table 84 | 85 | \item \code{avtable_delete_values(missing)}: Delete a row in a table based on the key 86 | 87 | \item \code{avtable_delete_values(ANY)}: Delete a row in a table based on the key 88 | 89 | }} 90 | \examples{ 91 | findMethods("avtable") 92 | getMethod("avtable", c(platform = "missing")) 93 | 94 | } 95 | -------------------------------------------------------------------------------- /R/avworkspace-methods.R: -------------------------------------------------------------------------------- 1 | #' @name avworkspace-methods 2 | #' 3 | #' @title The `avworkspace` methods for 'missing' and 'ANY' signatures 4 | #' 5 | #' @description The `AnVILBase` package defines S4 methods for the AnVIL 6 | #' package. These methods are defined for the 'missing' and 'ANY' signatures. 7 | #' 8 | #' @return Methods for the 'missing' and 'ANY' signatures provide a way to 9 | #' redirect calls to the appropriate method for the current cloud platform. 10 | #' 11 | #' @inheritParams AnVILBase-generics 12 | #' 13 | #' @examples 14 | #' findMethods("avworkspace") 15 | #' getMethod("avworkspace", c(platform = "missing")) 16 | #' 17 | NULL 18 | 19 | #' @describeIn avworkspace-methods Get the current workspace namespace/name 20 | #' @exportMethod avworkspace 21 | setMethod("avworkspace", c(platform = "missing"), function(..., platform) { 22 | avworkspace(..., platform = cloud_platform()) 23 | }) 24 | 25 | #' @describeIn avworkspace-methods Get the current workspace namespace/name 26 | #' @exportMethod avworkspace 27 | setMethod("avworkspace", c(platform = "ANY"), function(..., platform) { 28 | stop("'avworkspace()' not implemented for class ", class(platform)) 29 | }) 30 | 31 | #' @describeIn avworkspace-methods List workspaces 32 | #' @exportMethod avworkspaces 33 | setMethod("avworkspaces", c(platform = "missing"), function(..., platform) { 34 | avworkspaces(..., platform = cloud_platform()) 35 | }) 36 | 37 | #' @describeIn avworkspace-methods List workspaces 38 | #' @exportMethod avworkspaces 39 | setMethod("avworkspaces", c(platform = "ANY"), function(..., platform) { 40 | stop("'avworkspaces()' not implemented for class ", class(platform)) 41 | }) 42 | 43 | #' @describeIn avworkspace-methods Get the name of the current workspace 44 | #' @exportMethod avworkspace_name 45 | setMethod("avworkspace_name", c(platform = "missing"), 46 | function(..., platform) { 47 | avworkspace_name(..., platform = cloud_platform()) 48 | } 49 | ) 50 | 51 | #' @describeIn avworkspace-methods Get the name of the current workspace 52 | #' @exportMethod avworkspace_name 53 | setMethod("avworkspace_name", c(platform = "ANY"), function(..., platform) { 54 | stop("'avworkspace_name()' not implemented for class ", class(platform)) 55 | }) 56 | 57 | #' @describeIn avworkspace-methods Get the namespace of the current workspace 58 | #' @exportMethod avworkspace_namespace 59 | setMethod("avworkspace_namespace", c(platform = "missing"), 60 | function(..., platform) { 61 | avworkspace_namespace(..., platform = cloud_platform()) 62 | } 63 | ) 64 | 65 | #' @describeIn avworkspace-methods Get the namespace of the current workspace 66 | #' @exportMethod avworkspace_namespace 67 | setMethod("avworkspace_namespace", c(platform = "ANY"), 68 | function(..., platform) { 69 | stop( 70 | "'avworkspace_namespace()' not implemented for class ", 71 | class(platform) 72 | ) 73 | } 74 | ) 75 | 76 | #' @describeIn avworkspace-methods Clone the current workspace 77 | #' @exportMethod avworkspace_clone 78 | setMethod("avworkspace_clone", c(platform = "missing"), 79 | function(..., platform) { 80 | avworkspace_clone(..., platform = cloud_platform()) 81 | } 82 | ) 83 | 84 | #' @describeIn avworkspace-methods Clone the current workspace 85 | #' @exportMethod avworkspace_clone 86 | setMethod("avworkspace_clone", c(platform = "ANY"), function(..., platform) { 87 | stop("'avworkspace_clone()' not implemented for class ", class(platform)) 88 | }) 89 | -------------------------------------------------------------------------------- /R/AnVILBase-methods.R: -------------------------------------------------------------------------------- 1 | #' @name AnVILBase-methods 2 | #' 3 | #' @title The AnVILBase methods for 'missing' and 'ANY' signatures 4 | #' 5 | #' @description The `AnVILBase` package defines S4 methods for the AnVIL 6 | #' package. These methods are defined for the 'missing' and 'ANY' signatures. 7 | #' 8 | #' @inheritParams AnVILBase-generics 9 | #' 10 | #' @include AnVILBase-generics.R 11 | #' 12 | #' @return Methods for the 'missing' and 'ANY' signatures provide a way to 13 | #' redirect calls to the appropriate method for the current cloud platform. 14 | #' 15 | #' @examples 16 | #' findMethods("avcopy") 17 | #' getMethod("avcopy", c(platform = "missing")) 18 | #' 19 | #' 20 | NULL 21 | 22 | #' @describeIn AnVILBase-methods Copy a file from the cloud 23 | #' @exportMethod avcopy 24 | setMethod("avcopy", c(platform = "missing"), function(..., platform) { 25 | avcopy(..., platform = cloud_platform()) 26 | }) 27 | 28 | #' @describeIn AnVILBase-methods Copy a file from the cloud 29 | #' @exportMethod avcopy 30 | setMethod("avcopy", c(platform = "ANY"), function(..., platform) { 31 | stop("'avcopy()' not implemented for class ", class(platform)) 32 | }) 33 | 34 | #' @describeIn AnVILBase-methods List files in the cloud 35 | #' @exportMethod avlist 36 | setMethod("avlist", c(platform = "missing"), function(..., platform) { 37 | avlist(..., platform = cloud_platform()) 38 | }) 39 | 40 | #' @describeIn AnVILBase-methods List files in the cloud 41 | #' @exportMethod avlist 42 | setMethod("avlist", c(platform = "ANY"), function(..., platform) { 43 | stop("'avlist()' not implemented for class ", class(platform)) 44 | }) 45 | 46 | #' @describeIn AnVILBase-methods Remove a file from the cloud 47 | #' @exportMethod avremove 48 | setMethod("avremove", c(platform = "missing"), function(..., platform) { 49 | avremove(..., platform = cloud_platform()) 50 | }) 51 | 52 | #' @describeIn AnVILBase-methods Remove a file from the cloud 53 | #' @exportMethod avremove 54 | setMethod("avremove", c(platform = "ANY"), function(..., platform) { 55 | stop("'avremove()' not implemented for class ", class(platform)) 56 | }) 57 | 58 | #' @describeIn AnVILBase-methods Backup a file to the cloud 59 | #' @exportMethod avbackup 60 | setMethod("avbackup", c(platform = "missing"), function(..., platform) { 61 | avbackup(..., platform = cloud_platform()) 62 | }) 63 | 64 | #' @describeIn AnVILBase-methods Backup a file to the cloud 65 | #' @exportMethod avbackup 66 | setMethod("avbackup", c(platform = "ANY"), function(..., platform) { 67 | stop("'avbackup()' not implemented for class ", class(platform)) 68 | }) 69 | 70 | #' @describeIn AnVILBase-methods Restore a file from the cloud 71 | #' @exportMethod avrestore 72 | setMethod("avrestore", c(platform = "missing"), function(..., platform) { 73 | avrestore(..., platform = cloud_platform()) 74 | }) 75 | 76 | #' @describeIn AnVILBase-methods Restore a file from the cloud 77 | #' @exportMethod avrestore 78 | setMethod("avrestore", c(platform = "ANY"), function(..., platform) { 79 | stop("'avrestore()' not implemented for class ", class(platform)) 80 | }) 81 | 82 | #' @describeIn AnVILBase-methods Get the storage location 83 | #' @exportMethod avstorage 84 | setMethod("avstorage", c(platform = "missing"), function(..., platform) { 85 | avstorage(..., platform = cloud_platform()) 86 | }) 87 | 88 | #' @describeIn AnVILBase-methods Get the storage location 89 | #' @exportMethod avstorage 90 | setMethod("avstorage", c(platform = "ANY"), function(..., platform) { 91 | stop("'avstorage()' not implemented for class ", class(platform)) 92 | }) 93 | -------------------------------------------------------------------------------- /R/cloud_platform.R: -------------------------------------------------------------------------------- 1 | .get_env_opt <- 2 | function(envvar, option, default) 3 | { 4 | opt <- Sys.getenv(envvar, unset = default) 5 | getOption(option, opt) 6 | } 7 | 8 | #' @name cloud_platform 9 | #' 10 | #' @param default `character(1)`. The default cloud platform to use if no 11 | #' environment variables or options are set. The default is `""`. 12 | #' 13 | #' @return For `avplatform_namespace`: A character string indicating the cloud 14 | #' platform derived from environment variables. 15 | #' 16 | #' @export 17 | avplatform_namespace <- function(default = "") { 18 | opt <- .get_env_opt("GOOGLE_PROJECT", "GCLOUD_SDK_PATH", default) 19 | if (nzchar(opt)) 20 | return("AnVILGCP") 21 | 22 | opt <- .get_env_opt("WORKSPACE_ID", "AnVILAz.workspace_id", default) 23 | if (nzchar(opt)) 24 | return("AnVILAz") 25 | 26 | default 27 | } 28 | 29 | #' @title Cloud Platform Identifier 30 | #' 31 | #' @description `cloud_platform` calls the appropriate class constructor based 32 | #' on environment variables or options within the workspace. This function is 33 | #' used to determine the cloud platform to dispatch on for AnVIL methods. It 34 | #' returns an error when neither the Azure or Google Cloud environment 35 | #' variables are set. The `avplatform_namespace` function is a lower level 36 | #' helper to identify the platform based on environment variables or options. 37 | #' Generally, these functions are \emph{not} meant to be used directly. 38 | #' 39 | #' 40 | #' @details When `GOOGLE_PROJECT` is set, the function returns an object of 41 | #' class `gcp`. When `WORKSPACE_ID` is set, the function returns an object of 42 | #' class `azure`. Otherwise, the function returns an error. The user may also 43 | #' add options to set a default cloud platform. For AnVIL instances running on 44 | #' Google Cloud, the user can set 45 | #' `options(GCLOUD_SDK_PATH = "/home/user/google-cloud-sdk")` 46 | #' to set the default cloud platform to `gcp`. For AnVIL instances running on 47 | #' Azure, the user can set `options(AnVILAz.workspace_id = "myworkspace")` 48 | #' to set the default cloud platform to `azure`. Note that the values provided 49 | #' are example values and should be replaced with verifiable values. 50 | #' 51 | #' @return For `cloud_platform`: An instance of class `gcp` or `azure` based on 52 | #' environment variables or options set within the AnVIL workspace. For 53 | #' `avplatform_namespace`: A character string indicating the cloud platform. 54 | #' 55 | #' @examples 56 | #' avplatform_namespace() 57 | #' if (interactive()) { 58 | #' cloud_platform() 59 | #' } 60 | #' @export 61 | cloud_platform <- function() { 62 | switch( 63 | avplatform_namespace(), 64 | AnVILGCP = { 65 | if (requireNamespace("AnVILGCP", quietly = TRUE)) 66 | AnVILGCP::gcp() 67 | else 68 | stop("Install the 'AnVILGCP' package to use GCP on AnVIL.") 69 | }, 70 | AnVILAz = { 71 | if (requireNamespace("AnVILAz", quietly = TRUE)) 72 | AnVILAz::azure() 73 | else 74 | stop("Install the 'AnVILAz' package to use Azure on AnVIL.") 75 | }, 76 | { 77 | errmsg <- paste( 78 | strwrap( 79 | "The runtime environment must be within an AnVIL 80 | workspace. To diagnose, check the workspace environment 81 | variables and ensure that you have an associated 82 | 'GOOGLE_PROJECT' or 'WORKSPACE_ID' environment variable 83 | for Google Cloud and Azure workspaces, respectively." 84 | , exdent = 2L), 85 | collapse = "\n" 86 | ) 87 | stop(errmsg) 88 | } 89 | ) 90 | } 91 | -------------------------------------------------------------------------------- /vignettes/AnVILBaseIntroduction.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to AnVILBase" 3 | author: "Bioconductor AnVIL SIG" 4 | date: "`r format(Sys.time(), '%B %d, %Y')`" 5 | vignette: > 6 | %\VignetteIndexEntry{Introduction to AnVILBase} 7 | %\VignetteEngine{knitr::rmarkdown} 8 | %\VignetteEncoding{UTF-8} 9 | output: 10 | BiocStyle::html_document: 11 | number_sections: yes 12 | toc: true 13 | --- 14 | 15 | ```{r setup, include=FALSE} 16 | knitr::opts_chunk$set(echo = TRUE) 17 | ``` 18 | 19 | # Installation 20 | 21 | ```{r, eval=FALSE} 22 | if (!requireNamespace("BiocManager", quietly = TRUE)) 23 | install.packages("BiocManager") 24 | BiocManager::install("AnVILBase") 25 | ``` 26 | 27 | ```{r,include=TRUE,results="hide",message=FALSE,warning=FALSE} 28 | library(AnVILBase) 29 | ``` 30 | 31 | # Introduction 32 | 33 | The `AnVILBase` package defines S4 generics for AnVIL packages. The package is 34 | designed to be used in conjunction with either `AnVILGCP` or `AnVILAz` packages. 35 | The `AnVILBase` package is not intended to be used as a standalone package. 36 | 37 | # Overview 38 | 39 | The `AnVILBase` package defines S4 generics for the AnVIL package. These 40 | include methods for copying, listing, removing, and backing up files in the 41 | cloud. All generics in the package have methods defined for 'missing' and 'ANY' 42 | signatures. 43 | 44 | # Cloud Platforms 45 | 46 | The `AnVILBase` package is designed to support packages that work with the AnVIL 47 | cloud platforms. Downstream packages expose Google Cloud Platform (AnVILGCP) and 48 | the Azure Cloud Platform (AnVILAz) application programming interfaces (APIs). 49 | To increase usability, the `AnVILBase` package attempts to deduce the user's 50 | cloud platform from environment variables. This is codified in the 51 | `cloud_platform` function: 52 | 53 | ```{r,eval=FALSE} 54 | cloud_platform() 55 | ``` 56 | 57 | ### Developer Note 58 | 59 | Packages that use the `AnVILBase` package can conditionally run tests using the 60 | `avplatform_namespace()` function. It will return either `AnVILGCP` or `AnVILAz` 61 | depending on the cloud environment variables that are set. If no environment 62 | variables are set, the function will return `""`. 63 | 64 | ```{r} 65 | avplatform_namespace() 66 | ``` 67 | 68 | # Base generics 69 | 70 | The following generics are defined in the `AnVILBase` package: 71 | 72 | - `avcopy()`: Copy a file to and from the cloud 73 | - `avlist()`: List files in the cloud storage location 74 | - `avremove()`: Remove a file from the cloud 75 | - `avbackup()`: Backup files to the cloud 76 | - `avrestore()`: Restore files from the cloud 77 | - `avstorage()`: Get the storage address in the cloud 78 | 79 | # Table generics 80 | 81 | The following generics are defined in the `AnVILBase` package for tables: 82 | 83 | - `avtable` : Get a table by name from a workspace 84 | - `avtables` : List tables in the workspace(s) 85 | - `avtable_import`: Upload a table to a workspace 86 | - `avtable_import_set`: Create a set (grouped) table from an existing table 87 | - `avtable_delete`: Remove a table from a workspace 88 | - `avtable_delete_values`: Delete values from a table 89 | 90 | # Workspace generics 91 | 92 | The following generics are defined in the `AnVILBase` package for workspaces: 93 | 94 | - `avworkspace`: Set the active workspace 95 | - `avworkspaces`: List current workspace(s) on AnVIL 96 | - `avworkspace_name`: Get the workspace name 97 | - `avworkspace_namespace`: Get the workspace namespace 98 | 99 | Note that the `AnVILBase` package also includes helper functions that are 100 | used across `AnVIL` cloud platforms. These include functions mainly for working 101 | with the `AnVIL` API responses. 102 | 103 | # Workflow generics 104 | 105 | The following generics are defined in the `AnVILBase` package for workflows: 106 | 107 | - `avworkflow_jobs`: Get the execution status of a workflow 108 | 109 | # Notebook generics 110 | 111 | The following generics are defined in the `AnVILBase` package for notebooks: 112 | 113 | - `avnotebooks`: List notebooks in the workspace 114 | - `avnotebooks_localize`: Download notebooks from a cloud to a workspace 115 | - `avnotebooks_delocalize`: Upload notebooks from a workspace to a cloud 116 | 117 | # sessionInfo 118 | 119 | ```{r} 120 | sessionInfo() 121 | ``` 122 | 123 | -------------------------------------------------------------------------------- /R/avtable-methods.R: -------------------------------------------------------------------------------- 1 | #' @name avtable-methods 2 | #' 3 | #' @title The avtable methods for 'missing' and 'ANY' signatures 4 | #' 5 | #' @description The `AnVILBase` package defines S4 methods for the AnVIL 6 | #' package. These methods are defined for the 'missing' and 'ANY' signatures. 7 | #' 8 | #' @inheritParams avtable-generics 9 | #' 10 | #' @include avtable-generics.R 11 | #' 12 | #' @return Methods for the 'missing' and 'ANY' signatures provide a way to 13 | #' redirect calls to the appropriate method for the current cloud platform. 14 | #' 15 | #' @examples 16 | #' findMethods("avtable") 17 | #' getMethod("avtable", c(platform = "missing")) 18 | #' 19 | NULL 20 | 21 | #' @describeIn avtable-methods Show the contents of a particular table (entity 22 | #' / type) within a workspace. 23 | #' @exportMethod avtable 24 | setMethod("avtable", c(platform = "missing"), 25 | function(..., platform) { 26 | avtable(..., platform = cloud_platform()) 27 | } 28 | ) 29 | 30 | #' @describeIn avtable-methods Show the contents of a particular table (entity 31 | #' / type) within a workspace. 32 | #' @exportMethod avtable 33 | setMethod("avtable", c(platform = "ANY"), 34 | function(..., platform) { 35 | stop("'avtable()' not implemented for class ", class(platform)) 36 | } 37 | ) 38 | 39 | #' @describeIn avtable-methods List entities / types accross or within 40 | #' the current workspace respectively. 41 | #' @exportMethod avtables 42 | setMethod("avtables", c(platform = "missing"), 43 | function(..., platform) { 44 | avtables(..., platform = cloud_platform()) 45 | } 46 | ) 47 | 48 | #' @describeIn avtable-methods List entities / types accross or within 49 | #' the current workspace respectively. 50 | #' @exportMethod avtables 51 | setMethod("avtables", c(platform = "ANY"), 52 | function(..., platform) { 53 | stop("'avtables()' not implemented for class ", class(platform)) 54 | } 55 | ) 56 | 57 | #' @describeIn avtable-methods Upload a dataset to the DATA tab 58 | #' @exportMethod avtable_import 59 | setMethod("avtable_import", c(platform = "missing"), function(..., platform) { 60 | avtable_import(..., platform = cloud_platform()) 61 | }) 62 | 63 | #' @describeIn avtable-methods Upload a dataset to the DATA tab 64 | #' @exportMethod avtable_import 65 | setMethod("avtable_import", c(platform = "ANY"), function(..., platform) { 66 | stop("'avtable_import()' not implemented for class ", class(platform)) 67 | }) 68 | 69 | #' @describeIn avtable-methods Creates a grouping table for each 70 | #' distinct value in the column identified by `set`. 71 | #' @exportMethod avtable_import_set 72 | setMethod("avtable_import_set", c(platform = "missing"), 73 | function(..., platform) { 74 | avtable_import_set(..., platform = cloud_platform()) 75 | } 76 | ) 77 | 78 | #' @describeIn avtable-methods Creates a grouping table for each 79 | #' distinct value in the column identified by `set`. 80 | #' @exportMethod avtable_import_set 81 | setMethod("avtable_import_set", c(platform = "ANY"), function(..., platform) { 82 | stop( 83 | "'avtable_import_set()' not implemented for class ", class(platform) 84 | ) 85 | }) 86 | 87 | #' @describeIn avtable-methods Delete a table 88 | #' @exportMethod avtable_delete 89 | setMethod("avtable_delete", c(platform = "missing"), function(..., platform) { 90 | avtable_delete(..., platform = cloud_platform()) 91 | }) 92 | 93 | #' @describeIn avtable-methods Delete a table 94 | #' @exportMethod avtable_delete 95 | setMethod("avtable_delete", c(platform = "ANY"), function(..., platform) { 96 | stop("'avtable_delete()' not implemented for class ", class(platform)) 97 | }) 98 | 99 | #' @describeIn avtable-methods Delete a row in a table based on the key 100 | #' @exportMethod avtable_delete_values 101 | setMethod("avtable_delete_values", c(platform = "missing"), 102 | function(..., platform) { 103 | avtable_delete_values(..., platform = cloud_platform()) 104 | } 105 | ) 106 | 107 | #' @describeIn avtable-methods Delete a row in a table based on the key 108 | #' @exportMethod avtable_delete_values 109 | setMethod("avtable_delete_values", c(platform = "ANY"), 110 | function(..., platform) { 111 | stop( 112 | "'avtable_delete_values()' not implemented for class ", 113 | class(platform) 114 | ) 115 | } 116 | ) 117 | 118 | --------------------------------------------------------------------------------