Diff of /R/XenaBrowse.R [000000] .. [0bdad5]

Switch to unified view

a b/R/XenaBrowse.R
1
#' View Info of Dataset or Cohort at UCSC Xena Website Using Web browser
2
#'
3
#' This will open dataset/cohort link of UCSC Xena
4
#' in user's default browser.
5
#' @param x a [XenaHub] object.
6
#' @param type one of "dataset" and "cohort".
7
#' @param multiple if `TRUE`, browse multiple links instead of throwing error.
8
#' @importFrom utils URLencode browseURL
9
#' @export
10
#'
11
#' @examples
12
#' \donttest{
13
#' XenaGenerate(subset = XenaHostNames == "tcgaHub") %>%
14
#'   XenaFilter(filterDatasets = "clinical") %>%
15
#'   XenaFilter(filterDatasets = "LUAD") -> to_browse
16
#' }
17
XenaBrowse <- function(x, type = c("dataset", "cohort"), multiple = FALSE) { # nocov start
18
  if (!inherits(x, "XenaHub")) {
19
    stop("Input x must be a XenaHub object.")
20
  }
21
22
  type <- match.arg(type)
23
24
  if (type == "dataset") {
25
    all_datasets <- datasets(x)
26
    if (length(all_datasets) != 1) {
27
      if (!multiple) stop("This function limite 1 dataset to browse.\n Set multiple to TRUE if you want to browse multiple links.")
28
      for (i in all_datasets) {
29
        xe_tmp <- XenaFilter(x,
30
          filterDatasets = i,
31
          ignore.case = FALSE, fixed = TRUE
32
        )
33
        y <- utils::URLencode(
34
          paste0(
35
            "https://xenabrowser.net/datapages/?",
36
            "dataset=", datasets(xe_tmp),
37
            "&host=", hosts(xe_tmp)
38
          )
39
        )
40
        utils::browseURL(y)
41
      }
42
    } else {
43
      y <- utils::URLencode(
44
        paste0(
45
          "https://xenabrowser.net/datapages/?",
46
          "dataset=", datasets(x),
47
          "&host=", hosts(x)
48
        )
49
      )
50
      utils::browseURL(y)
51
    }
52
  } else {
53
    all_cohorts <- cohorts(x)
54
    if (length(all_cohorts) != 1) {
55
      if (!multiple) stop("This function limite 1 cohort to browse. \n Set multiple to TRUE if you want to browse multiple links.")
56
      for (i in all_cohorts) {
57
        xe_tmp <- XenaFilter(x,
58
          filterCohorts = i,
59
          ignore.case = FALSE, fixed = TRUE
60
        )
61
        y <- utils::URLencode(
62
          paste0(
63
            "https://xenabrowser.net/datapages/?",
64
            "cohort=", cohorts(xe_tmp)
65
          )
66
        )
67
        utils::browseURL(y)
68
      }
69
    } else {
70
      y <- utils::URLencode(
71
        paste0(
72
          "https://xenabrowser.net/datapages/?",
73
          "cohort=", cohorts(x)
74
        )
75
      )
76
      utils::browseURL(y)
77
    }
78
  }
79
80
  invisible(NULL)
81
} # nocov end
82
83
utils::globalVariables(c("XenaDatasets", "XenaHosts", "ProbeMap"))