diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b2ebad68..0cbf1669 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -18,8 +18,8 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: 'release'} + - {os: macOS-13, r: 'release'} + - {os: windows-2022, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} @@ -29,7 +29,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -40,9 +40,18 @@ jobs: use-public-rspm: true - uses: r-lib/actions/setup-r-dependencies@v2 + id: install-deps + continue-on-error: true with: extra-packages: any::rcmdcheck needs: check + + - name: If source build fails on macOS or Windows, fall back to typical install + if: steps.install-deps.outcome == 'failure' + shell: Rscript {0} + run: | + reticulate::install_miniconda() + install.packages("synapser", repos="http://ran.synapse.org") - uses: r-lib/actions/check-r-package@v2 with: diff --git a/DESCRIPTION b/DESCRIPTION index 9e74f721..526aaaba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,7 +40,8 @@ Imports: emoji, plyr, readxl, - yaml + yaml, + synapser (>= 1.0.0) URL: https://github.com/nf-osi/nfportalutils BugReports: https://github.com/nf-osi/nfportalutils/issues Suggests: @@ -50,3 +51,5 @@ Suggests: withr Config/testthat/edition: 2 VignetteBuilder: knitr +Remotes: + github::Sage-Bionetworks/synapser diff --git a/R/add_publication_from_unpaywall.R b/R/add_publication_from_unpaywall.R index 28c33b3d..b4269b2d 100644 --- a/R/add_publication_from_unpaywall.R +++ b/R/add_publication_from_unpaywall.R @@ -130,20 +130,4 @@ add_publication_from_unpaywall <- function(publication_table_id, } }} -#' Adds a row to a table. -#' @param schema A synapse table Schema object. -#' @param new_row A data frame of one or more rows that match the provided schema. -#' @export -.store_rows <- function(schema, new_row){ - - table <- .syn$store(synapseclient$Table(schema, new_row)) - -} - -# .pluck_column_type_and_name <- function(column){ -# coltype <- purrr::pluck(column, "columnType") -# name <- purrr::pluck(column, "name") -# -# c(coltype, name) -# } diff --git a/R/basic_utils.R b/R/basic_utils.R index 99308fcb..b80d51c7 100644 --- a/R/basic_utils.R +++ b/R/basic_utils.R @@ -82,3 +82,21 @@ walk <- function(syn_id, as_list = TRUE) { } + +#' Adds a row to a table. +#' @param schema A synapse table Schema object. +#' @param new_row A data frame of one or more rows that match the provided schema. +#' @export +.store_rows <- function(schema, new_row){ + + table <- synapser::synStore(synapser::Table(schema, new_row)) + +} + +# .pluck_column_type_and_name <- function(column){ +# coltype <- purrr::pluck(column, "columnType") +# name <- purrr::pluck(column, "name") +# +# c(coltype, name) +# } + diff --git a/R/login.R b/R/login.R index 374fa970..9225a677 100644 --- a/R/login.R +++ b/R/login.R @@ -1,9 +1,9 @@ #' Logs into Synapse. -#' +#' #' Wrapper around https://python-docs.synapse.org/build/html/index.html#synapseclient.Synapse.login #' Username and password authentication is not supported. #' Recommendation is to store `SYNAPSE_AUTH_TOKEN` in environment, so login can be used simply as `syn_login()`. -#' +#' #' @param authtoken Uses `SYNAPSE_AUTH_TOKEN` environmental variable, or a personal access token (PAT) can be provided. #' @examples #' \dontrun{ @@ -22,9 +22,7 @@ syn_login <- function(authtoken = Sys.getenv("SYNAPSE_AUTH_TOKEN")){ #' @returns A message. #' @keywords internal .check_login <- function(){ - if(!exists(".syn")){ - stop('Please run `nfportalutils::syn_login()` prior to running functions that require a connection to Synapse. (Alternatively, the Python `synapseclient` is unavailable.)') - }else if(capture.output(.syn) == ""){ - stop('Please run `nfportalutils::syn_login()` prior to running functions that require a connection to Synapse. (Alternatively, the Python `synapseclient` is unavailable.)') + if(!exists(".syn") & !exists("syn")){ + stop('Please run `nfportalutils::syn_login()` or `synapser::synLogin()` prior to running functions that require a connection to Synapse. (Alternatively, the Python `synapseclient` is unavailable.)') } } diff --git a/R/update_people_table.R b/R/update_people_table.R index d1fee286..e575f70f 100644 --- a/R/update_people_table.R +++ b/R/update_people_table.R @@ -1,7 +1,7 @@ #' Update the People table from a source Table or View column -#' +#' #' @param people_table_id The synapse id of the table used for referencing people. -#' @param people_column Column name within the people table that contains the relevant people values. +#' @param people_column Column name within the people table that contains the relevant people values. #' @param source_table_id The synapse id of the source table. #' @param source_column Column name within the source table that contains the relevant source values. #' @inheritParams update_study_annotations @@ -15,7 +15,8 @@ add_people_from_table <- function(people_table_id, people_column, source_table_i #get current people ids old_people_query <- glue::glue("select {people_column} from {people_table_id}") - old_people <- .syn$tableQuery(old_people_query)$asDataFrame() %>% + old_people <- synapser::synTableQuery(old_people_query, includeRowIdAndRowVersion = F)$asDataFrame() %>% + tibble::as_tibble() %>% dplyr::distinct() old_ids <- old_people[[{{people_column}}]] @@ -23,7 +24,8 @@ add_people_from_table <- function(people_table_id, people_column, source_table_i #get ids from new source table new_people_query <- glue::glue("select {source_column} from {source_table_id}") - new_people <- .syn$tableQuery(new_people_query)$asDataFrame() %>% + new_people <- synapser::synTableQuery(new_people_query, includeRowIdAndRowVersion = F)$asDataFrame() %>% + tibble::as_tibble() %>% dplyr::distinct() %>% dplyr::filter(!(!!rlang::sym(source_column)) %in% old_ids) %>% #filter out existing ids purrr::pluck(source_column) @@ -32,7 +34,7 @@ add_people_from_table <- function(people_table_id, people_column, source_table_i new_rows <- tibble::tibble(!!people_column := new_people) - schema <- .syn$get(people_table_id) + schema <- synapser::synGet(people_table_id) if(dry_run == F){ .store_rows(schema, new_rows) diff --git a/man/dot-store_rows.Rd b/man/dot-store_rows.Rd index bbbaa84d..22394c72 100644 --- a/man/dot-store_rows.Rd +++ b/man/dot-store_rows.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/add_publication_from_unpaywall.R +% Please edit documentation in R/basic_utils.R \name{.store_rows} \alias{.store_rows} \title{Adds a row to a table.}