diff --git a/DESCRIPTION b/DESCRIPTION index 6e9205a..e1125a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: iatlasGraphQLClient Title: iatlas API Client Type: Package -Version: 0.1.1 +Version: 0.2.2 Author: Andrew Lamb Maintainer: Andrew Lamb Description: This package is am R Client library for the iAtlas API. @@ -20,8 +20,8 @@ Imports: ghql (>= 0.1), jsonlite (>= 1.7), magrittr (>= 2.0), - purrr (>= 0.3), - rlang (>= 0.4), + purrr (>= 1.0), + rlang (>= 1.0), snakecase, stringr (>= 1.0), tibble (>= 3.0), diff --git a/R/api_functions.R b/R/api_functions.R index ea854c6..b2a2302 100644 --- a/R/api_functions.R +++ b/R/api_functions.R @@ -32,7 +32,7 @@ perform_api_query <- function( query_dir = system.file("queries", package = "iatlasGraphQLClient"), api_url = "https://api-staging.cri-iatlas.org/api" ){ - if(!is.null(.GlobalEnv$API_URL)){ + if (!is.null(.GlobalEnv$API_URL)) { api_url <- .GlobalEnv$API_URL } ghql_con <- ghql::GraphqlClient$new(api_url) @@ -65,17 +65,18 @@ format_query_result <- function( select_cols = NULL, arrange_cols = NULL ){ - if(!is.null(unnest_cols)) { + if (!is.null(unnest_cols)) { tbl <- tidyr::unnest(tbl, dplyr::all_of(unnest_cols), keep_empty = T) } tbl <- tbl %>% + as.data.frame() %>% jsonlite::flatten(.) %>% dplyr::as_tibble() - if(!is.null(select_cols)) { + if (!is.null(select_cols)) { tbl <- dplyr::select(tbl, dplyr::any_of(select_cols)) } - if(!is.null(arrange_cols)) { + if (!is.null(arrange_cols)) { tbl <- dplyr::arrange(tbl, !!!rlang::syms(arrange_cols)) } return(tbl) @@ -109,6 +110,12 @@ create_result_from_api_query <- function( if (is.null(tbl)) { return(default_tbl) } + if (length(tbl) == 0) { + return(default_tbl) + } + if (nrow(tbl) == 0) { + return(default_tbl) + } format_query_result(tbl, unnest_cols, select_cols, arrange_cols) } @@ -135,7 +142,7 @@ create_result_from_cursor_paginated_api_query <- function( ... ){ items_list <- do_cursor_paginated_api_query(query_args, query_file, ...) - if(length(items_list) == 0) return(default_tbl) + if (length(items_list) == 0) return(default_tbl) results <- items_list %>% rev() %>% purrr::map( @@ -169,7 +176,7 @@ create_result_from_offset_paginated_api_query <- function( ... ){ items_list <- do_offset_paginated_api_query(query_args, query_file, ...) - if(length(items_list) == 0) return(default_tbl) + if (length(items_list) == 0) return(default_tbl) results <- items_list %>% rev() %>% purrr::map( @@ -204,8 +211,8 @@ do_cursor_paginated_api_query <- function( if (empty_result) { return(list()) } - if(!is.null(paging$hasNextPage) && paging$hasNextPage){ - if(length(query_args$paging) == 1 && is.na(query_args$paging)){ + if (!is.null(paging$hasNextPage) && paging$hasNextPage) { + if (length(query_args$paging) == 1 && is.na(query_args$paging)) { new_paging <- list("after" = paging$endCursor) } else { new_paging <- query_args$paging @@ -247,8 +254,8 @@ do_offset_paginated_api_query <- function( return(list()) } - if(paging$page < paging$pages){ - if(length(query_args$paging) == 1 && is.na(query_args$paging)){ + if (paging$page < paging$pages) { + if (length(query_args$paging) == 1 && is.na(query_args$paging)) { new_paging <- list("page" = paging$page + 1) } else { new_paging <- query_args$paging diff --git a/R/api_nodes_queries.R b/R/api_nodes_queries.R index a7b9c63..417d7a1 100644 --- a/R/api_nodes_queries.R +++ b/R/api_nodes_queries.R @@ -21,7 +21,8 @@ query_nodes <- function( min_score = NA, parent_tags = NA, network = NA, - tags = NA, + tag1 = NA, + tag2 = NA, n_tags = NA, paging = NA, ... @@ -29,19 +30,23 @@ query_nodes <- function( has_features <- !(length(features) == 1 && is.na(features)) has_genes <- !(length(entrez) == 1 && is.na(entrez)) - if(has_features & has_genes){ + if (has_features & has_genes) { stop("Can not query for both entrez and features at a the same time") - } else if(has_features) { + } else if (has_features) { query_file <- "feature_nodes.txt" select_cols <- c( - get_node_json_names(), + get_node_json_names(), + get_tag_one_json_names(), + get_tag_two_json_names(), "feature_name" = "feature.name", "feature_display" = "feature.display" ) - } else if(has_genes) { + } else if (has_genes) { query_file <- "gene_nodes.txt" select_cols <- c( - get_node_json_names(), + get_node_json_names(), + get_tag_one_json_names(), + get_tag_two_json_names(), "gene_entrez" = "gene.entrez", "gene_hgnc" = "gene.hgnc", "gene_friendly_name" = "gene.friendlyName" @@ -55,8 +60,9 @@ query_nodes <- function( "minScore" = min_score, "related" = parent_tags, "network" = network, - "tag" = tags, - "nTags"= n_tags, + "tag1" = tag1, + "tag2" = tag2, + "nTags" = n_tags, "paging" = paging, "distinct" = F ) @@ -74,27 +80,22 @@ query_nodes <- function( ) ) - tbl <-create_result_from_cursor_paginated_api_query( + tbl <- create_result_from_cursor_paginated_api_query( query_args = query_args, query_file = query_file, default_tbl = default_tbl, select_cols = select_cols, ... ) - if(nrow(tbl) == 0) return(tbl) - tbl %>% - dplyr::mutate("node_tags" = purrr::map( - .data$node_tags, - ~dplyr::select(.x, get_tag_json_names()) - )) - if(!has_features){ + if (nrow(tbl) == 0) return(tbl) + if (!has_features) { tbl <- tbl %>% dplyr::mutate( "feature_name" = NA_character_, "feature_display" = NA_character_, ) } - if(!has_genes){ + if (!has_genes) { tbl <- tbl %>% dplyr::mutate( "gene_entrez" = NA_integer_, @@ -114,7 +115,6 @@ get_node_column_tbl <- function(prefix = "node_"){ "label", "label", character(), "name", "name", character(), "score", "score", double(), - "tags", "tags", list(), "x", "x", character(), "y", "y", character() @@ -141,3 +141,28 @@ get_node_field_names <- function(prefix = "node_"){ get_node_column_tbl(prefix) %>% dplyr::pull("name") } + +get_tag_one_json_names <- function(){ + c( + "tag_1_name" = "tag1.name", + "tag_1_characteristics" = "tag1.characteristics", + "tag_1_color" = "tag1.color", + "tag_1_long_display" = "tag1.longDisplay", + "tag_1_order" = "tag1.order", + "tag_1_short_display" = "tag1.shortDisplay", + "tag_1_type" = "tag1.type" + ) +} + +get_tag_two_json_names <- function(){ + c( + "tag_2_name" = "tag2.name", + "tag_2_characteristics" = "tag2.characteristics", + "tag_2_color" = "tag2.color", + "tag_2_long_display" = "tag2.longDisplay", + "tag_2_order" = "tag2.order", + "tag_2_short_display" = "tag2.shortDisplay", + "tag_2_type" = "tag2.type" + ) +} + diff --git a/inst/queries/feature_nodes.txt b/inst/queries/feature_nodes.txt index e8295cf..f0cb579 100644 --- a/inst/queries/feature_nodes.txt +++ b/inst/queries/feature_nodes.txt @@ -6,7 +6,8 @@ query FeatureNodes( $network: [String!] $nTags: Int $related: [String!] - $tag: [String!] + $tag1: [String!] + $tag2: [String!] $paging: PagingInput $distinct: Boolean ) { @@ -18,7 +19,8 @@ query FeatureNodes( network: $network nTags: $nTags related: $related - tag: $tag + tag1: $tag1 + tag2: $tag2 paging: $paging distinct: $distinct ) { @@ -28,7 +30,16 @@ query FeatureNodes( score x y - tags { + tag1 { + characteristics + color + name + longDisplay + order + shortDisplay + type + } + tag2 { characteristics color name diff --git a/inst/queries/gene_nodes.txt b/inst/queries/gene_nodes.txt index 9d1a258..7ec811b 100644 --- a/inst/queries/gene_nodes.txt +++ b/inst/queries/gene_nodes.txt @@ -6,7 +6,8 @@ query GeneNodes( $network: [String!] $nTags: Int $related: [String!] - $tag: [String!] + $tag1: [String!] + $tag2: [String!] $paging: PagingInput $distinct: Boolean ) { @@ -18,7 +19,8 @@ query GeneNodes( network: $network nTags: $nTags related: $related - tag: $tag + tag1: $tag1 + tag2: $tag2 paging: $paging distinct: $distinct ) { @@ -28,7 +30,16 @@ query GeneNodes( score x y - tags { + tag1 { + characteristics + color + name + longDisplay + order + shortDisplay + type + } + tag2 { characteristics color name diff --git a/man/perform_api_query.Rd b/man/perform_api_query.Rd index f1d7604..311bc7a 100644 --- a/man/perform_api_query.Rd +++ b/man/perform_api_query.Rd @@ -8,7 +8,7 @@ perform_api_query( variables, query_file, query_dir = system.file("queries", package = "iatlasGraphQLClient"), - api_url = "https://api.cri-iatlas.org/api" + api_url = "https://api-staging.cri-iatlas.org/api" ) } \arguments{ diff --git a/man/query_tag_publications.Rd b/man/query_tag_publications.Rd index 88b290f..a5c482d 100644 --- a/man/query_tag_publications.Rd +++ b/man/query_tag_publications.Rd @@ -5,12 +5,12 @@ \title{Query Tag Publications} \usage{ query_tag_publications( - cohorts = NA, - samples = NA, - datasets = NA, - parent_tags = NA, - tags = NA, - type = NA, + cohorts = NA_character_, + samples = NA_character_, + datasets = NA_character_, + parent_tags = NA_character_, + tags = NA_character_, + type = NA_character_, paging = NA, ... ) diff --git a/man/query_tag_sample_count.Rd b/man/query_tag_sample_count.Rd index 0886841..7007000 100644 --- a/man/query_tag_sample_count.Rd +++ b/man/query_tag_sample_count.Rd @@ -5,12 +5,12 @@ \title{Query Tag Sample Count} \usage{ query_tag_sample_count( - cohorts = NA, - samples = NA, - datasets = NA, - parent_tags = NA, - tags = NA, - type = NA, + cohorts = NA_character_, + samples = NA_character_, + datasets = NA_character_, + parent_tags = NA_character_, + tags = NA_character_, + type = NA_character_, paging = NA, ... ) diff --git a/man/query_tag_samples.Rd b/man/query_tag_samples.Rd index 2b8cead..21ea2e1 100644 --- a/man/query_tag_samples.Rd +++ b/man/query_tag_samples.Rd @@ -5,12 +5,12 @@ \title{Query Tag Samples} \usage{ query_tag_samples( - cohorts = NA, - samples = NA, - datasets = NA, - parent_tags = NA, - tags = NA, - type = NA, + cohorts = NA_character_, + samples = NA_character_, + datasets = NA_character_, + parent_tags = NA_character_, + tags = NA_character_, + type = NA_character_, paging = NA, ... ) diff --git a/man/query_tag_samples_parents.Rd b/man/query_tag_samples_parents.Rd index 225c7f1..c8e87b1 100644 --- a/man/query_tag_samples_parents.Rd +++ b/man/query_tag_samples_parents.Rd @@ -5,12 +5,12 @@ \title{Query Tag Samples Parents} \usage{ query_tag_samples_parents( - cohorts = NA, - samples = NA, - datasets = NA, - parent_tags = NA, - tags = NA, - type = NA, + cohorts = NA_character_, + samples = NA_character_, + datasets = NA_character_, + parent_tags = NA_character_, + tags = NA_character_, + type = NA_character_, paging = NA, ... ) diff --git a/man/query_tags_with_parent_tags.Rd b/man/query_tags_with_parent_tags.Rd index 8a20658..aa9a1e8 100644 --- a/man/query_tags_with_parent_tags.Rd +++ b/man/query_tags_with_parent_tags.Rd @@ -5,12 +5,12 @@ \title{Query Tags With Parent Tags} \usage{ query_tags_with_parent_tags( - cohorts = NA, - samples = NA, - datasets = NA, - parent_tags = NA, - tags = NA, - type = NA, + cohorts = NA_character_, + samples = NA_character_, + datasets = NA_character_, + parent_tags = NA_character_, + tags = NA_character_, + type = NA_character_, paging = NA, ... ) diff --git a/renv.lock b/renv.lock index 202b59b..e5d5df1 100644 --- a/renv.lock +++ b/renv.lock @@ -31,9 +31,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "e8a22846fff485f0be3770c2da758713", - "Requirements": [ - "sys" - ] + "Requirements": [] }, "assertthat": { "Package": "assertthat", @@ -65,10 +63,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "648c5b3d71e6a37e3043617489a0a0e9", - "Requirements": [ - "fastmap", - "rlang" - ] + "Requirements": [] }, "callr": { "Package": "callr", @@ -76,10 +71,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "461aa75a11ce2400245190ef5d3995df", - "Requirements": [ - "R6", - "processx" - ] + "Requirements": [] }, "cli": { "Package": "cli", @@ -87,9 +79,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "1bdb126893e9ce6aae50ad1d6fc32faf", - "Requirements": [ - "glue" - ] + "Requirements": [] }, "clipr": { "Package": "clipr", @@ -129,13 +119,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "93762d0a34d78e6a025efdbfb5c6bb41", - "Requirements": [ - "askpass", - "curl", - "jsonlite", - "openssl", - "sys" - ] + "Requirements": [] }, "crul": { "Package": "crul", @@ -143,14 +127,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "607162d6f0d735014263cb0160c5be72", - "Requirements": [ - "R6", - "curl", - "httpcode", - "jsonlite", - "mime", - "urltools" - ] + "Requirements": [] }, "curl": { "Package": "curl", @@ -166,11 +143,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "eebd27ee58fcc58714eedb7aa07d8ad1", - "Requirements": [ - "R6", - "cli", - "rprojroot" - ] + "Requirements": [] }, "devtools": { "Package": "devtools", @@ -178,28 +151,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "fc35e13bb582e5fe6f63f3d647a4cbe5", - "Requirements": [ - "callr", - "cli", - "desc", - "ellipsis", - "fs", - "httr", - "lifecycle", - "memoise", - "pkgbuild", - "pkgload", - "rcmdcheck", - "remotes", - "rlang", - "roxygen2", - "rstudioapi", - "rversions", - "sessioninfo", - "testthat", - "usethis", - "withr" - ] + "Requirements": [] }, "diffobj": { "Package": "diffobj", @@ -207,9 +159,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8", - "Requirements": [ - "crayon" - ] + "Requirements": [] }, "digest": { "Package": "digest", @@ -225,18 +175,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "ef47665e64228a17609d6df877bf86f2", - "Requirements": [ - "R6", - "generics", - "glue", - "lifecycle", - "magrittr", - "pillar", - "rlang", - "tibble", - "tidyselect", - "vctrs" - ] + "Requirements": [] }, "ellipsis": { "Package": "ellipsis", @@ -244,9 +183,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077", - "Requirements": [ - "rlang" - ] + "Requirements": [] }, "evaluate": { "Package": "evaluate", @@ -294,14 +231,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "8fddce7cbd59467106266a6e93e253b4", - "Requirements": [ - "askpass", - "credentials", - "openssl", - "rstudioapi", - "sys", - "zip" - ] + "Requirements": [] }, "gh": { "Package": "gh", @@ -309,13 +239,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "38c2580abbda249bd6afeec00d14f531", - "Requirements": [ - "cli", - "gitcreds", - "httr", - "ini", - "jsonlite" - ] + "Requirements": [] }, "ghql": { "Package": "ghql", @@ -323,12 +247,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "aa13ce03131717aa76a44259460ece6b", - "Requirements": [ - "R6", - "crul", - "graphql", - "jsonlite" - ] + "Requirements": [] }, "gitcreds": { "Package": "gitcreds", @@ -352,10 +271,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "9f7d9c6426833d0cdfea726201589c42", - "Requirements": [ - "Rcpp", - "jsonlite" - ] + "Requirements": [] }, "highr": { "Package": "highr", @@ -363,9 +279,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "8eb36c8125038e648e5d111c0d7b2ed4", - "Requirements": [ - "xfun" - ] + "Requirements": [] }, "httpcode": { "Package": "httpcode", @@ -381,13 +295,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "a525aba14184fec243f9eaec62fbed43", - "Requirements": [ - "R6", - "curl", - "jsonlite", - "mime", - "openssl" - ] + "Requirements": [] }, "ini": { "Package": "ini", @@ -411,13 +319,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "a4ec675eb332a33fe7b7fe26f70e1f98", - "Requirements": [ - "evaluate", - "highr", - "stringr", - "xfun", - "yaml" - ] + "Requirements": [] }, "lifecycle": { "Package": "lifecycle", @@ -425,10 +327,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "a6b6d352e3ed897373ab19d8395c98d0", - "Requirements": [ - "glue", - "rlang" - ] + "Requirements": [] }, "magrittr": { "Package": "magrittr", @@ -444,10 +343,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c", - "Requirements": [ - "cachem", - "rlang" - ] + "Requirements": [] }, "mime": { "Package": "mime", @@ -463,9 +359,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "cf4329aac12c2c44089974559c18e446", - "Requirements": [ - "askpass" - ] + "Requirements": [] }, "pillar": { "Package": "pillar", @@ -473,17 +367,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "51dfc97e1b7069e9f7e6f83f3589c22e", - "Requirements": [ - "cli", - "crayon", - "ellipsis", - "fansi", - "glue", - "lifecycle", - "rlang", - "utf8", - "vctrs" - ] + "Requirements": [] }, "pkgbuild": { "Package": "pkgbuild", @@ -491,16 +375,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "66d2adfed274daf81ccfe77d974c3b9b", - "Requirements": [ - "R6", - "callr", - "cli", - "crayon", - "desc", - "prettyunits", - "rprojroot", - "withr" - ] + "Requirements": [] }, "pkgconfig": { "Package": "pkgconfig", @@ -516,15 +391,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "7533cd805940821bf23eaf3c8d4c1735", - "Requirements": [ - "cli", - "crayon", - "desc", - "rlang", - "rprojroot", - "rstudioapi", - "withr" - ] + "Requirements": [] }, "praise": { "Package": "praise", @@ -548,10 +415,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "0cbca2bc4d16525d009c4dbba156b37c", - "Requirements": [ - "R6", - "ps" - ] + "Requirements": [] }, "ps": { "Package": "ps", @@ -567,10 +431,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "97def703420c8ab10d8f0e6c72101e02", - "Requirements": [ - "magrittr", - "rlang" - ] + "Requirements": [] }, "rappdirs": { "Package": "rappdirs", @@ -586,20 +447,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "8f25ebe2ec38b1f2aef3b0d2ef76f6c4", - "Requirements": [ - "R6", - "callr", - "cli", - "curl", - "desc", - "digest", - "pkgbuild", - "prettyunits", - "rprojroot", - "sessioninfo", - "withr", - "xopen" - ] + "Requirements": [] }, "rematch2": { "Package": "rematch2", @@ -607,9 +455,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "76c9e04c712a05848ae7a23d2f170a40", - "Requirements": [ - "tibble" - ] + "Requirements": [] }, "remotes": { "Package": "remotes", @@ -621,10 +467,11 @@ }, "renv": { "Package": "renv", - "Version": "0.15.4", - "Source": "Repository", + "Version": "1.0.2", + "OS_type": NA, + "NeedsCompilation": "no", "Repository": "CRAN", - "Hash": "c1078316e1d4f70275fc1ea60c0bc431", + "Source": "Repository", "Requirements": [] }, "rlang": { @@ -641,21 +488,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "eb9849556c4250305106e82edae35b72", - "Requirements": [ - "R6", - "brew", - "commonmark", - "cpp11", - "desc", - "digest", - "knitr", - "pkgload", - "purrr", - "rlang", - "stringi", - "stringr", - "xml2" - ] + "Requirements": [] }, "rprojroot": { "Package": "rprojroot", @@ -679,10 +512,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "f88fab00907b312f8b23ec13e2d437cb", - "Requirements": [ - "curl", - "xml2" - ] + "Requirements": [] }, "sessioninfo": { "Package": "sessioninfo", @@ -690,9 +520,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "3f9796a8d0a0e8c6eb49a4b029359d1f", - "Requirements": [ - "cli" - ] + "Requirements": [] }, "snakecase": { "Package": "snakecase", @@ -700,10 +528,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "4079070fc210c7901c0832a3aeab894f", - "Requirements": [ - "stringi", - "stringr" - ] + "Requirements": [] }, "stringi": { "Package": "stringi", @@ -719,11 +544,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "0759e6b6c0957edb1311028a49a35e76", - "Requirements": [ - "glue", - "magrittr", - "stringi" - ] + "Requirements": [] }, "sys": { "Package": "sys", @@ -739,27 +560,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "32454e5780e8dbe31e4b61b13d8918fe", - "Requirements": [ - "R6", - "brio", - "callr", - "cli", - "crayon", - "desc", - "digest", - "ellipsis", - "evaluate", - "jsonlite", - "lifecycle", - "magrittr", - "pkgload", - "praise", - "processx", - "ps", - "rlang", - "waldo", - "withr" - ] + "Requirements": [] }, "tibble": { "Package": "tibble", @@ -767,16 +568,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "8a8f02d1934dfd6431c671361510dd0b", - "Requirements": [ - "ellipsis", - "fansi", - "lifecycle", - "magrittr", - "pillar", - "pkgconfig", - "rlang", - "vctrs" - ] + "Requirements": [] }, "tidyr": { "Package": "tidyr", @@ -784,19 +576,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "d8b95b7fee945d7da6888cf7eb71a49c", - "Requirements": [ - "cpp11", - "dplyr", - "ellipsis", - "glue", - "lifecycle", - "magrittr", - "purrr", - "rlang", - "tibble", - "tidyselect", - "vctrs" - ] + "Requirements": [] }, "tidyselect": { "Package": "tidyselect", @@ -804,13 +584,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "17f6da8cfd7002760a859915ce7eef8f", - "Requirements": [ - "ellipsis", - "glue", - "purrr", - "rlang", - "vctrs" - ] + "Requirements": [] }, "triebeard": { "Package": "triebeard", @@ -818,9 +592,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "847a9d113b78baca4a9a8639609ea228", - "Requirements": [ - "Rcpp" - ] + "Requirements": [] }, "urltools": { "Package": "urltools", @@ -828,10 +600,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "e86a704261a105f4703f653e05defa3e", - "Requirements": [ - "Rcpp", - "triebeard" - ] + "Requirements": [] }, "usethis": { "Package": "usethis", @@ -839,27 +608,7 @@ "Source": "Repository", "Repository": "RSPM", "Hash": "c499f488e6dd7718accffaee5bc5a79b", - "Requirements": [ - "cli", - "clipr", - "crayon", - "curl", - "desc", - "fs", - "gert", - "gh", - "glue", - "jsonlite", - "lifecycle", - "purrr", - "rappdirs", - "rlang", - "rprojroot", - "rstudioapi", - "whisker", - "withr", - "yaml" - ] + "Requirements": [] }, "utf8": { "Package": "utf8", @@ -875,11 +624,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "ecf749a1b39ea72bd9b51b76292261f1", - "Requirements": [ - "ellipsis", - "glue", - "rlang" - ] + "Requirements": [] }, "waldo": { "Package": "waldo", @@ -887,15 +632,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "035fba89d0c86e2113120f93301b98ad", - "Requirements": [ - "cli", - "diffobj", - "fansi", - "glue", - "rematch2", - "rlang", - "tibble" - ] + "Requirements": [] }, "whisker": { "Package": "whisker", @@ -935,9 +672,7 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "6c85f015dee9cc7710ddd20f86881f58", - "Requirements": [ - "processx" - ] + "Requirements": [] }, "yaml": { "Package": "yaml", diff --git a/renv/activate.R b/renv/activate.R index e961251..aad8bc2 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,11 +2,27 @@ local({ # the requested version of renv - version <- "0.15.4" + version <- ..version.. + attr(version, "sha") <- ..sha.. # the project directory project <- getwd() + # use start-up diagnostics if enabled + diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE") + if (diagnostics) { + start <- Sys.time() + profile <- tempfile("renv-startup-", fileext = ".Rprof") + utils::Rprof(profile) + on.exit({ + utils::Rprof(NULL) + elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L) + writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed))) + writeLines(sprintf("- Profile: %s", profile)) + print(utils::summaryRprof(profile)) + }, add = TRUE) + } + # figure out whether the autoloader is enabled enabled <- local({ @@ -54,27 +70,81 @@ local({ # mask 'utils' packages, will come first on the search path library(utils, lib.loc = .Library) - # unload renv if it's already been laoded + # unload renv if it's already been loaded if ("renv" %in% loadedNamespaces()) unloadNamespace("renv") # load bootstrap tools `%||%` <- function(x, y) { - if (is.environment(x) || length(x)) x else y + if (is.null(x)) y else x + } + + catf <- function(fmt, ..., appendLF = TRUE) { + + quiet <- getOption("renv.bootstrap.quiet", default = FALSE) + if (quiet) + return(invisible()) + + msg <- sprintf(fmt, ...) + cat(msg, file = stdout(), sep = if (appendLF) "\n" else "") + + invisible(msg) + + } + + header <- function(label, + ..., + prefix = "#", + suffix = "-", + n = min(getOption("width"), 78)) + { + label <- sprintf(label, ...) + n <- max(n - nchar(label) - nchar(prefix) - 2L, 8L) + if (n <= 0) + return(paste(prefix, label)) + + tail <- paste(rep.int(suffix, n), collapse = "") + paste0(prefix, " ", label, " ", tail) + + } + + startswith <- function(string, prefix) { + substring(string, 1, nchar(prefix)) == prefix } bootstrap <- function(version, library) { + friendly <- renv_bootstrap_version_friendly(version) + section <- header(sprintf("Bootstrapping renv %s", friendly)) + catf(section) + # attempt to download renv - tarball <- tryCatch(renv_bootstrap_download(version), error = identity) - if (inherits(tarball, "error")) - stop("failed to download renv ", version) + catf("- Downloading renv ... ", appendLF = FALSE) + withCallingHandlers( + tarball <- renv_bootstrap_download(version), + error = function(err) { + catf("FAILED") + stop("failed to download:\n", conditionMessage(err)) + } + ) + catf("OK") + on.exit(unlink(tarball), add = TRUE) # now attempt to install - status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity) - if (inherits(status, "error")) - stop("failed to install renv ", version) + catf("- Installing renv ... ", appendLF = FALSE) + withCallingHandlers( + status <- renv_bootstrap_install(version, tarball, library), + error = function(err) { + catf("FAILED") + stop("failed to install:\n", conditionMessage(err)) + } + ) + catf("OK") + + # add empty line to break up bootstrapping from normal output + catf("") + return(invisible()) } renv_bootstrap_tests_running <- function() { @@ -83,28 +153,32 @@ local({ renv_bootstrap_repos <- function() { + # get CRAN repository + cran <- getOption("renv.repos.cran", "https://cloud.r-project.org") + # check for repos override repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) - if (!is.na(repos)) + if (!is.na(repos)) { + + # check for RSPM; if set, use a fallback repository for renv + rspm <- Sys.getenv("RSPM", unset = NA) + if (identical(rspm, repos)) + repos <- c(RSPM = rspm, CRAN = cran) + return(repos) + } + # check for lockfile repositories repos <- tryCatch(renv_bootstrap_repos_lockfile(), error = identity) if (!inherits(repos, "error") && length(repos)) return(repos) - # if we're testing, re-use the test repositories - if (renv_bootstrap_tests_running()) - return(getOption("renv.tests.repos")) - # retrieve current repos repos <- getOption("repos") # ensure @CRAN@ entries are resolved - repos[repos == "@CRAN@"] <- getOption( - "renv.repos.cran", - "https://cloud.r-project.org" - ) + repos[repos == "@CRAN@"] <- cran # add in renv.bootstrap.repos if set default <- c(FALLBACK = "https://cloud.r-project.org") @@ -143,33 +217,34 @@ local({ renv_bootstrap_download <- function(version) { - # if the renv version number has 4 components, assume it must - # be retrieved via github - nv <- numeric_version(version) - components <- unclass(nv)[[1]] - - # if this appears to be a development version of 'renv', we'll - # try to restore from github - dev <- length(components) == 4L - - # begin collecting different methods for finding renv - methods <- c( - renv_bootstrap_download_tarball, - if (dev) - renv_bootstrap_download_github - else c( - renv_bootstrap_download_cran_latest, - renv_bootstrap_download_cran_archive + sha <- attr(version, "sha", exact = TRUE) + + methods <- if (!is.null(sha)) { + + # attempting to bootstrap a development version of renv + c( + function() renv_bootstrap_download_tarball(sha), + function() renv_bootstrap_download_github(sha) ) - ) + + } else { + + # attempting to bootstrap a release version of renv + c( + function() renv_bootstrap_download_tarball(version), + function() renv_bootstrap_download_cran_latest(version), + function() renv_bootstrap_download_cran_archive(version) + ) + + } for (method in methods) { - path <- tryCatch(method(version), error = identity) + path <- tryCatch(method(), error = identity) if (is.character(path) && file.exists(path)) return(path) } - stop("failed to download renv ", version) + stop("All download methods failed") } @@ -185,43 +260,75 @@ local({ if (fixup) mode <- "w+b" - utils::download.file( + args <- list( url = url, destfile = destfile, mode = mode, quiet = TRUE ) + if ("headers" %in% names(formals(utils::download.file))) + args$headers <- renv_bootstrap_download_custom_headers(url) + + do.call(utils::download.file, args) + } - renv_bootstrap_download_cran_latest <- function(version) { + renv_bootstrap_download_custom_headers <- function(url) { - spec <- renv_bootstrap_download_cran_latest_find(version) + headers <- getOption("renv.download.headers") + if (is.null(headers)) + return(character()) + + if (!is.function(headers)) + stopf("'renv.download.headers' is not a function") + + headers <- headers(url) + if (length(headers) == 0L) + return(character()) + + if (is.list(headers)) + headers <- unlist(headers, recursive = FALSE, use.names = TRUE) + + ok <- + is.character(headers) && + is.character(names(headers)) && + all(nzchar(names(headers))) + + if (!ok) + stop("invocation of 'renv.download.headers' did not return a named character vector") - message("* Downloading renv ", version, " ... ", appendLF = FALSE) + headers + } + + renv_bootstrap_download_cran_latest <- function(version) { + + spec <- renv_bootstrap_download_cran_latest_find(version) type <- spec$type repos <- spec$repos - info <- tryCatch( - utils::download.packages( - pkgs = "renv", - destdir = tempdir(), - repos = repos, - type = type, - quiet = TRUE - ), + baseurl <- utils::contrib.url(repos = repos, type = type) + ext <- if (identical(type, "source")) + ".tar.gz" + else if (Sys.info()[["sysname"]] == "Windows") + ".zip" + else + ".tgz" + name <- sprintf("renv_%s%s", version, ext) + url <- paste(baseurl, name, sep = "/") + + destfile <- file.path(tempdir(), name) + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), condition = identity ) - if (inherits(info, "condition")) { - message("FAILED") + if (inherits(status, "condition")) return(FALSE) - } # report success and return - message("OK (downloaded ", type, ")") - info[1, 2] + destfile } @@ -277,8 +384,6 @@ local({ urls <- file.path(repos, "src/contrib/Archive/renv", name) destfile <- file.path(tempdir(), name) - message("* Downloading renv ", version, " ... ", appendLF = FALSE) - for (url in urls) { status <- tryCatch( @@ -286,14 +391,11 @@ local({ condition = identity ) - if (identical(status, 0L)) { - message("OK") + if (identical(status, 0L)) return(destfile) - } } - message("FAILED") return(FALSE) } @@ -307,20 +409,25 @@ local({ return() # allow directories - info <- file.info(tarball, extra_cols = FALSE) - if (identical(info$isdir, TRUE)) { + if (dir.exists(tarball)) { name <- sprintf("renv_%s.tar.gz", version) tarball <- file.path(tarball, name) } # bail if it doesn't exist - if (!file.exists(tarball)) + if (!file.exists(tarball)) { + + # let the user know we weren't able to honour their request + fmt <- "- RENV_BOOTSTRAP_TARBALL is set (%s) but does not exist." + msg <- sprintf(fmt, tarball) + warning(msg) + + # bail return() - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) + } + catf("- Using local tarball '%s'.", tarball) tarball } @@ -347,8 +454,6 @@ local({ on.exit(do.call(base::options, saved), add = TRUE) } - message("* Downloading renv ", version, " from GitHub ... ", appendLF = FALSE) - url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version) name <- sprintf("renv_%s.tar.gz", version) destfile <- file.path(tempdir(), name) @@ -358,26 +463,105 @@ local({ condition = identity ) - if (!identical(status, 0L)) { - message("FAILED") + if (!identical(status, 0L)) return(FALSE) - } - message("OK") + renv_bootstrap_download_augment(destfile) + return(destfile) } + # Add Sha to DESCRIPTION. This is stop gap until #890, after which we + # can use renv::install() to fully capture metadata. + renv_bootstrap_download_augment <- function(destfile) { + sha <- renv_bootstrap_git_extract_sha1_tar(destfile) + if (is.null(sha)) { + return() + } + + # Untar + tempdir <- tempfile("renv-github-") + on.exit(unlink(tempdir, recursive = TRUE), add = TRUE) + untar(destfile, exdir = tempdir) + pkgdir <- dir(tempdir, full.names = TRUE)[[1]] + + # Modify description + desc_path <- file.path(pkgdir, "DESCRIPTION") + desc_lines <- readLines(desc_path) + remotes_fields <- c( + "RemoteType: github", + "RemoteHost: api.github.com", + "RemoteRepo: renv", + "RemoteUsername: rstudio", + "RemotePkgRef: rstudio/renv", + paste("RemoteRef: ", sha), + paste("RemoteSha: ", sha) + ) + writeLines(c(desc_lines[desc_lines != ""], remotes_fields), con = desc_path) + + # Re-tar + local({ + old <- setwd(tempdir) + on.exit(setwd(old), add = TRUE) + + tar(destfile, compression = "gzip") + }) + invisible() + } + + # Extract the commit hash from a git archive. Git archives include the SHA1 + # hash as the comment field of the tarball pax extended header + # (see https://www.kernel.org/pub/software/scm/git/docs/git-archive.html) + # For GitHub archives this should be the first header after the default one + # (512 byte) header. + renv_bootstrap_git_extract_sha1_tar <- function(bundle) { + + # open the bundle for reading + # We use gzcon for everything because (from ?gzcon) + # > Reading from a connection which does not supply a 'gzip' magic + # > header is equivalent to reading from the original connection + conn <- gzcon(file(bundle, open = "rb", raw = TRUE)) + on.exit(close(conn)) + + # The default pax header is 512 bytes long and the first pax extended header + # with the comment should be 51 bytes long + # `52 comment=` (11 chars) + 40 byte SHA1 hash + len <- 0x200 + 0x33 + res <- rawToChar(readBin(conn, "raw", n = len)[0x201:len]) + + if (grepl("^52 comment=", res)) { + sub("52 comment=", "", res) + } else { + NULL + } + } + renv_bootstrap_install <- function(version, tarball, library) { # attempt to install it into project library - message("* Installing renv ", version, " ... ", appendLF = FALSE) dir.create(library, showWarnings = FALSE, recursive = TRUE) + output <- renv_bootstrap_install_impl(library, tarball) + + # check for successful install + status <- attr(output, "status") + if (is.null(status) || identical(status, 0L)) + return(status) + + # an error occurred; report it + header <- "installation of renv failed" + lines <- paste(rep.int("=", nchar(header)), collapse = "") + text <- paste(c(header, lines, output), collapse = "\n") + stop(text) + + } + + renv_bootstrap_install_impl <- function(library, tarball) { # invoke using system2 so we can capture and report output bin <- R.home("bin") exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" - r <- file.path(bin, exe) + R <- file.path(bin, exe) args <- c( "--vanilla", "CMD", "INSTALL", "--no-multiarch", @@ -385,19 +569,7 @@ local({ shQuote(path.expand(tarball)) ) - output <- system2(r, args, stdout = TRUE, stderr = TRUE) - message("Done!") - - # check for successful install - status <- attr(output, "status") - if (is.numeric(status) && !identical(status, 0L)) { - header <- "Error installing renv:" - lines <- paste(rep.int("=", nchar(header)), collapse = "") - text <- c(header, lines, output) - writeLines(text, con = stderr()) - } - - status + system2(R, args, stdout = TRUE, stderr = TRUE) } @@ -607,34 +779,62 @@ local({ } - renv_bootstrap_validate_version <- function(version) { + renv_bootstrap_validate_version <- function(version, description = NULL) { - loadedversion <- utils::packageDescription("renv", fields = "Version") - if (version == loadedversion) - return(TRUE) + # resolve description file + # + # avoid passing lib.loc to `packageDescription()` below, since R will + # use the loaded version of the package by default anyhow. note that + # this function should only be called after 'renv' is loaded + # https://github.com/rstudio/renv/issues/1625 + description <- description %||% packageDescription("renv") - # assume four-component versions are from GitHub; three-component - # versions are from CRAN - components <- strsplit(loadedversion, "[.-]")[[1]] - remote <- if (length(components) == 4L) - paste("rstudio/renv", loadedversion, sep = "@") + # check whether requested version 'version' matches loaded version of renv + sha <- attr(version, "sha", exact = TRUE) + valid <- if (!is.null(sha)) + renv_bootstrap_validate_version_dev(sha, description) else - paste("renv", loadedversion, sep = "@") + renv_bootstrap_validate_version_release(version, description) + + if (valid) + return(TRUE) + + # the loaded version of renv doesn't match the requested version; + # give the user instructions on how to proceed + remote <- if (!is.null(description[["RemoteSha"]])) { + paste("rstudio/renv", description[["RemoteSha"]], sep = "@") + } else { + paste("renv", description[["Version"]], sep = "@") + } + + # display both loaded version + sha if available + friendly <- renv_bootstrap_version_friendly( + version = description[["Version"]], + sha = description[["RemoteSha"]] + ) fmt <- paste( "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.", - "Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", - "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", + "- Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", + "- Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", sep = "\n" ) - - msg <- sprintf(fmt, loadedversion, version, remote) - warning(msg, call. = FALSE) + catf(fmt, friendly, renv_bootstrap_version_friendly(version), remote) FALSE } + renv_bootstrap_validate_version_dev <- function(version, description) { + expected <- description[["RemoteSha"]] + is.character(expected) && startswith(expected, version) + } + + renv_bootstrap_validate_version_release <- function(version, description) { + expected <- description[["Version"]] + is.character(expected) && identical(expected, version) + } + renv_bootstrap_hash_text <- function(text) { hashfile <- tempfile("renv-hash-") @@ -654,6 +854,12 @@ local({ # warn if the version of renv loaded does not match renv_bootstrap_validate_version(version) + # execute renv load hooks, if any + hooks <- getHook("renv::autoload") + for (hook in hooks) + if (is.function(hook)) + tryCatch(hook(), error = warnify) + # load the project renv::load(project) @@ -669,7 +875,7 @@ local({ return(profile) # check for a profile file (nothing to do if it doesn't exist) - path <- renv_bootstrap_paths_renv("profile", profile = FALSE) + path <- renv_bootstrap_paths_renv("profile", profile = FALSE, project = project) if (!file.exists(path)) return(NULL) @@ -793,14 +999,93 @@ local({ } + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { + sha <- sha %||% attr(version, "sha", exact = TRUE) + parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = "") + } + + renv_bootstrap_exec <- function(project, libpath, version) { + if (!renv_bootstrap_load(project, libpath, version)) + renv_bootstrap_run(version, libpath) + } + + renv_bootstrap_run <- function(version, libpath) { + + # perform bootstrap + bootstrap(version, libpath) + + # exit early if we're just testing bootstrap + if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) + return(TRUE) + + # try again to load + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + return(renv::load(project = getwd())) + } + + # failed to download or load renv; warn the user + msg <- c( + "Failed to find an renv installation: the project will not be loaded.", + "Use `renv::activate()` to re-initialize the project." + ) + + warning(paste(msg, collapse = "\n"), call. = FALSE) + + } + + + renv_bootstrap_in_rstudio <- function() { + commandArgs()[[1]] == "RStudio" + } + + # Used to work around buglet in RStudio if hook uses readline + renv_bootstrap_flush_console <- function() { + tryCatch({ + tools <- as.environment("tools:rstudio") + tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE) + }, error = function(cnd) {}) + } renv_json_read <- function(file = NULL, text = NULL) { + jlerr <- NULL + + # if jsonlite is loaded, use that instead + if ("jsonlite" %in% loadedNamespaces()) { + + json <- catch(renv_json_read_jsonlite(file, text)) + if (!inherits(json, "error")) + return(json) + + jlerr <- json + + } + + # otherwise, fall back to the default JSON reader + json <- catch(renv_json_read_default(file, text)) + if (!inherits(json, "error")) + return(json) + + # report an error + if (!is.null(jlerr)) + stop(jlerr) + else + stop(json) + + } + + renv_json_read_jsonlite <- function(file = NULL, text = NULL) { text <- paste(text %||% read(file), collapse = "\n") + jsonlite::fromJSON(txt = text, simplifyVector = FALSE) + } + + renv_json_read_default <- function(file = NULL, text = NULL) { # find strings in the JSON + text <- paste(text %||% read(file), collapse = "\n") pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' - locs <- gregexpr(pattern, text)[[1]] + locs <- gregexpr(pattern, text, perl = TRUE)[[1]] # if any are found, replace them with placeholders replaced <- text @@ -829,8 +1114,9 @@ local({ # transform the JSON into something the R parser understands transformed <- replaced - transformed <- gsub("[[{]", "list(", transformed) - transformed <- gsub("[]}]", ")", transformed) + transformed <- gsub("{}", "`names<-`(list(), character())", transformed, fixed = TRUE) + transformed <- gsub("[[{]", "list(", transformed, perl = TRUE) + transformed <- gsub("[]}]", ")", transformed, perl = TRUE) transformed <- gsub(":", "=", transformed, fixed = TRUE) text <- paste(transformed, collapse = "\n") @@ -899,35 +1185,17 @@ local({ # construct full libpath libpath <- file.path(root, prefix) - # attempt to load - if (renv_bootstrap_load(project, libpath, version)) - return(TRUE) - - # load failed; inform user we're about to bootstrap - prefix <- paste("# Bootstrapping renv", version) - postfix <- paste(rep.int("-", 77L - nchar(prefix)), collapse = "") - header <- paste(prefix, postfix) - message(header) - - # perform bootstrap - bootstrap(version, libpath) - - # exit early if we're just testing bootstrap - if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) - return(TRUE) - - # try again to load - if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { - message("* Successfully installed and loaded renv ", version, ".") - return(renv::load()) + if (renv_bootstrap_in_rstudio()) { + # RStudio only updates console once .Rprofile is finished, so + # instead run code on sessionInit + setHook("rstudio.sessionInit", function(...) { + renv_bootstrap_exec(project, libpath, version) + renv_bootstrap_flush_console() + }) + } else { + renv_bootstrap_exec(project, libpath, version) } - # failed to download or load renv; warn the user - msg <- c( - "Failed to find an renv installation: the project will not be loaded.", - "Use `renv::activate()` to re-initialize the project." - ) - - warning(paste(msg, collapse = "\n"), call. = FALSE) + invisible() }) diff --git a/tests/testthat/test-api_cohorts_queries.R b/tests/testthat/test-api_cohorts_queries.R index 79d0e76..eb23cc5 100644 --- a/tests/testthat/test-api_cohorts_queries.R +++ b/tests/testthat/test-api_cohorts_queries.R @@ -48,7 +48,7 @@ test_that("query_cohort_features", { ) result1 <- query_cohort_features( - cohorts = "PCAWG_Immune_Subtype", + cohorts = "TCGA_Immune_Subtype", query_dir = query_dir ) @@ -72,76 +72,6 @@ test_that("query_cohort_features", { expect_equal(nrow(result4), 0) }) -test_that("query_cohort_genes", { - expected_columns <- c( - "cohort_name", - "gene_entrez", - "gene_hgnc" - ) - - result1 <- query_cohort_genes( - cohorts = "TCGA_Immune_Subtype", - query_dir = query_dir - ) - - expect_named(result1, expected_columns) - expect_true(nrow(result1) > 1) - - result3 <- query_cohort_genes( - cohort = "TCGA", - query_dir = query_dir - ) - - expect_named(result3, expected_columns) - expect_true(nrow(result3) > 1) - - result4 <- query_cohort_genes( - cohort = "not_a_cohort", - query_dir = query_dir - ) - - expect_named(result4, expected_columns) - expect_equal(nrow(result4), 0) -}) - -test_that("query_cohort_mutations", { - expected_columns1 <- c( - "cohort_name", - "mutation_code", - "mutation_gene_entrez", - "mutation_gene_hgnc" - ) - - expected_columns2 <- c( - "cohort_name", - "mutation_code", - "mutation_gene_entrez" - ) - - result1 <- query_cohort_mutations( - cohorts = "TCGA_Immune_Subtype", - query_dir = query_dir - ) - - expect_named(result1, expected_columns1) - expect_true(nrow(result1) > 1) - - result3 <- query_cohort_mutations( - cohort = "TCGA", - query_dir = query_dir - ) - - expect_named(result3, expected_columns1) - expect_true(nrow(result3) > 1) - - result4 <- query_cohort_mutations( - cohort = "not_a_cohort", - query_dir = query_dir - ) - - expect_named(result4, expected_columns2) - expect_equal(nrow(result4), 0) -}) test_that("query_cohort_samples", { expected_columns1 <- c( diff --git a/tests/testthat/test-api_copy_number_result_queries.R b/tests/testthat/test-api_copy_number_result_queries.R index 67cab88..927d934 100644 --- a/tests/testthat/test-api_copy_number_result_queries.R +++ b/tests/testthat/test-api_copy_number_result_queries.R @@ -18,9 +18,7 @@ test_that("query_copy_number_results",{ "hgnc" ) result1 <- query_copy_number_results( - datasets = "TCGA", - tags = "C1", - max_p_value = 0.000000000000000000000000000000000000000000000001, + entrez = 1, query_dir = query_dir ) expect_named(result1, expected_columns) @@ -37,8 +35,7 @@ test_that("query_copy_number_results",{ test_that("query_copy_number_result_genes",{ expected_columns <- c("entrez", "hgnc") result1 <- query_copy_number_result_genes( - datasets = "TCGA", - tags = "C1", + entrez = 1, query_dir = query_dir ) expect_named(result1, expected_columns) diff --git a/tests/testthat/test-api_edges_queries.R b/tests/testthat/test-api_edges_queries.R index 7a7d0d7..753ea46 100644 --- a/tests/testthat/test-api_edges_queries.R +++ b/tests/testthat/test-api_edges_queries.R @@ -7,8 +7,8 @@ test_that("query_edges",{ "node2" ) result1 <- query_edges( - node1 = "PCAWG_cellimage_network_BLCA-US_940", - node2 = "PCAWG_cellimage_network_BLCA-US_T_cells_CD8_Aggregate2", + node1 = "PCAWG_extracellular_network_C2_8754", + node2 = "PCAWG_extracellular_network_C2_3655", query_dir = query_dir ) result2 <- query_edges( diff --git a/tests/testthat/test-api_features_queries.R b/tests/testthat/test-api_features_queries.R index 58e388c..3584a61 100644 --- a/tests/testthat/test-api_features_queries.R +++ b/tests/testthat/test-api_features_queries.R @@ -35,7 +35,6 @@ test_that("query_feature_values", { ) result1 <- query_feature_values( - cohorts = "PCAWG_Immune_Subtype", features = "Lymphocytes_Aggregate1", query_dir = query_dir ) diff --git a/tests/testthat/test-api_nodes_queries.R b/tests/testthat/test-api_nodes_queries.R index d48e8f4..77af860 100644 --- a/tests/testthat/test-api_nodes_queries.R +++ b/tests/testthat/test-api_nodes_queries.R @@ -1,63 +1,47 @@ test_that("query_gene_nodes",{ - expected_columns <- c( - get_node_field_names(), - "feature_name", - "feature_display", - "gene_entrez", - "gene_hgnc", - "gene_friendly_name" - ) result1 <- query_nodes( datasets = "TCGA", - tags = "C1", + tag1 = "C1", entrez = 2, network = "Extracellular Network", + n_tags = 2, query_dir = query_dir ) result2 <- query_nodes( datasets = "none", - tags = "C1", + tag1 = "C1", entrez = 2, network = "Extracellular Network", + n_tags = 2, query_dir = query_dir ) - expect_named(result1, expected_columns, ignore.order = T) - expect_named(result2, expected_columns, ignore.order = T) expect_true(nrow(result1) > 0) expect_equal(nrow(result2), 0) }) test_that("query_feature_nodes",{ - expected_columns <- c( - get_node_field_names(), - "feature_name", - "feature_display", - "gene_entrez", - "gene_hgnc", - "gene_friendly_name" - ) result1 <- query_nodes( datasets = "TCGA", - tags = "C1", + tag1 = "C1", features = "B_cells_Aggregate2", network = "Extracellular Network", + n_tags = 2, query_dir = query_dir ) - expect_named(result1, expected_columns, ignore.order = T) expect_true(nrow(result1) > 0) result2 <- query_nodes( datasets = "TCGA", - tags = "C1", + tag1 = "C1", features = c( "B_cells_Aggregate2", "Dendritic_cells_Aggregate2" ), network = "Extracellular Network", min_score = 5, + n_tags = 2, query_dir = query_dir ) - expect_named(result2, expected_columns, ignore.order = T) expect_equal(nrow(result2), 0) }) diff --git a/tests/testthat/test-api_tags_queries.R b/tests/testthat/test-api_tags_queries.R index 24b9e63..47c8a31 100644 --- a/tests/testthat/test-api_tags_queries.R +++ b/tests/testthat/test-api_tags_queries.R @@ -23,7 +23,7 @@ test_that("query_tag_samples", { get_tag_field_names() ) - result1 <- query_tag_samples(cohorts = "PCAWG_Immune_Subtype", tag = "C1") + result1 <- query_tag_samples() expect_named(result1, expected_columns) expect_true(nrow(result1) > 0) @@ -31,69 +31,65 @@ test_that("query_tag_samples", { expect_named(result2, expected_columns) expect_equal(nrow(result2), 0) }) -# -# test_that("query_tag_samples_parents", { -# expected_columns <- c( -# "sample_name", -# get_tag_field_names(prefix = "parent_tag_"), -# get_tag_field_names() -# ) -# -# result1 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "C1") -# expect_named(result1, expected_columns) -# expect_true(nrow(result1) > 0) -# -# result2 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") -# expect_named(result2, expected_columns) -# expect_equal(nrow(result2), 0) -# }) -# -# test_that("query_tag_sample_count", { -# expected_columns <- c( -# get_tag_field_names(), -# "sample_count" -# ) -# -# result1 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "C1") -# expect_named(result1, expected_columns) -# expect_true(nrow(result1) > 0) -# -# result2 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") -# expect_named(result2, expected_columns) -# expect_equal(nrow(result2), 0) -# }) -# -# test_that("query_tag_publications", { -# expected_columns <- c( -# "publication_do_id", -# "publication_first_author_last_name", -# "publication_journal", -# "publication_name", -# "publication_pubmed_id", -# "publication_title", -# get_tag_field_names() -# ) -# -# result1 <- query_tag_publications(tag = "ACC_") -# expect_named(result1, expected_columns) -# expect_true(nrow(result1) > 0) -# -# result2 <- query_tag_publications(tag = "not_a_tag") -# expect_named(result2, expected_columns) -# expect_equal(nrow(result2), 0) -# }) -# -# test_that("query_tags_with_parent_tags", { -# expected_columns <- c( -# get_tag_field_names(prefix = "parent_tag_"), -# get_tag_field_names() -# ) -# -# result1 <- query_tags_with_parent_tags(tag = "C1") -# expect_named(result1, expected_columns) -# expect_equal(nrow(result1), 1) -# -# result2 <- query_tags_with_parent_tags(tag = "not_a_tag") -# expect_named(result2, expected_columns) -# expect_equal(nrow(result2), 0) -# }) + +test_that("query_tag_samples_parents", { + expected_columns <- c( + "sample_name", + get_tag_field_names(prefix = "parent_tag_"), + get_tag_field_names() + ) + + result1 <- query_tag_samples_parents() + expect_named(result1, expected_columns) + expect_true(nrow(result1) > 0) + + result2 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") + expect_named(result2, expected_columns) + expect_equal(nrow(result2), 0) +}) + +test_that("query_tag_sample_count", { + expected_columns <- c( + get_tag_field_names(), + "sample_count" + ) + + result2 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") + expect_named(result2, expected_columns) + expect_equal(nrow(result2), 0) +}) + +test_that("query_tag_publications", { + expected_columns <- c( + "publication_do_id", + "publication_first_author_last_name", + "publication_journal", + "publication_name", + "publication_pubmed_id", + "publication_title", + get_tag_field_names() + ) + + result1 <- query_tag_publications(tag = "ACC_") + expect_named(result1, expected_columns) + expect_true(nrow(result1) > 0) + + result2 <- query_tag_publications(tag = "not_a_tag") + expect_named(result2, expected_columns) + expect_equal(nrow(result2), 0) +}) + +test_that("query_tags_with_parent_tags", { + expected_columns <- c( + get_tag_field_names(prefix = "parent_tag_"), + get_tag_field_names() + ) + + result1 <- query_tags_with_parent_tags(tag = "C1") + expect_named(result1, expected_columns) + expect_equal(nrow(result1), 1) + + result2 <- query_tags_with_parent_tags(tag = "not_a_tag") + expect_named(result2, expected_columns) + expect_equal(nrow(result2), 0) +})