From 7a31fba64ac00b2273943eb9378e8de8f3f4834b Mon Sep 17 00:00:00 2001 From: Anh Nguyet Vu <32753274+anngvu@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:52:57 -0600 Subject: [PATCH] Downclimb in develop (#180) * Revert "change people functions to synapser (#168)" This reverts commit 4320d35b99b48466de41c5337e0ff6dd8da5b2f4. * Update README --- .github/workflows/R-CMD-check.yaml | 15 +++------------ DESCRIPTION | 5 +---- R/add_publication_from_unpaywall.R | 16 ++++++++++++++++ R/basic_utils.R | 18 ------------------ R/login.R | 10 ++++++---- R/update_people_table.R | 12 +++++------- README.md | 12 +++++++++--- man/dot-store_rows.Rd | 2 +- 8 files changed, 41 insertions(+), 49 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0cbf1669..b2ebad68 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-13, r: 'release'} - - {os: windows-2022, r: 'release'} + - {os: macOS-latest, r: 'release'} + - {os: windows-latest, 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@v4 + - uses: actions/checkout@v2 - uses: r-lib/actions/setup-pandoc@v2 @@ -40,18 +40,9 @@ 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 526aaaba..9e74f721 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,8 +40,7 @@ Imports: emoji, plyr, readxl, - yaml, - synapser (>= 1.0.0) + yaml URL: https://github.com/nf-osi/nfportalutils BugReports: https://github.com/nf-osi/nfportalutils/issues Suggests: @@ -51,5 +50,3 @@ 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 b4269b2d..28c33b3d 100644 --- a/R/add_publication_from_unpaywall.R +++ b/R/add_publication_from_unpaywall.R @@ -130,4 +130,20 @@ 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 b80d51c7..99308fcb 100644 --- a/R/basic_utils.R +++ b/R/basic_utils.R @@ -82,21 +82,3 @@ 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 9225a677..374fa970 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,7 +22,9 @@ syn_login <- function(authtoken = Sys.getenv("SYNAPSE_AUTH_TOKEN")){ #' @returns A message. #' @keywords internal .check_login <- function(){ - 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.)') + 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.)') } } diff --git a/R/update_people_table.R b/R/update_people_table.R index e575f70f..d1fee286 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,8 +15,7 @@ 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 <- synapser::synTableQuery(old_people_query, includeRowIdAndRowVersion = F)$asDataFrame() %>% - tibble::as_tibble() %>% + old_people <- .syn$tableQuery(old_people_query)$asDataFrame() %>% dplyr::distinct() old_ids <- old_people[[{{people_column}}]] @@ -24,8 +23,7 @@ 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 <- synapser::synTableQuery(new_people_query, includeRowIdAndRowVersion = F)$asDataFrame() %>% - tibble::as_tibble() %>% + new_people <- .syn$tableQuery(new_people_query)$asDataFrame() %>% dplyr::distinct() %>% dplyr::filter(!(!!rlang::sym(source_column)) %in% old_ids) %>% #filter out existing ids purrr::pluck(source_column) @@ -34,7 +32,7 @@ add_people_from_table <- function(people_table_id, people_column, source_table_i new_rows <- tibble::tibble(!!people_column := new_people) - schema <- synapser::synGet(people_table_id) + schema <- .syn$get(people_table_id) if(dry_run == F){ .store_rows(schema, new_rows) diff --git a/README.md b/README.md index 586697ab..88690d7c 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,20 @@ You can install `nfportalutils` from here: remotes::install_github("nf-osi/nfportalutils") ``` +The package interops with the [Python synapse client](https://github.com/Sage-Bionetworks/synapsePythonClient) via reticulate. +You will have to download the Python synapse client first. - -## Additional Notes for Users +## For Users - View function reference on docs site at [Reference](https://nf-osi.github.io/nfportalutils/reference/index.html). - An alternative to viewing vignettes as Articles on the [docs site](https://nf-osi.github.io/nfportalutils/index.html) is to download them with pkg install and load with e.g. `vignette("annotate-nf-processed-data", package = "nfportalutils")` to view. -## Additional Notes for Contributors +## For Contributors + +### General picture +- Again, default development happens in `develop`. +- But we have a side branch called `develop-synapser` where interop tries to transition to `synapser`. +However, current coexistence makes development a bit tricky so consult first before trying new developments there. ### Contrib workflow - Branch of `develop` and make changes diff --git a/man/dot-store_rows.Rd b/man/dot-store_rows.Rd index 22394c72..bbbaa84d 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/basic_utils.R +% Please edit documentation in R/add_publication_from_unpaywall.R \name{.store_rows} \alias{.store_rows} \title{Adds a row to a table.}