Skip to content

Commit

Permalink
feat: add $ method for auto-completion
Browse files Browse the repository at this point in the history
  • Loading branch information
js2264 committed Sep 1, 2023
1 parent e34ba86 commit 207a5d8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(.DollarNames,GInteractions)
S3method(arrange,GInteractions)
S3method(as_ginteractions,data.frame)
S3method(as_ginteractions,default)
Expand All @@ -23,6 +24,7 @@ export(strand1)
export(strand2)
export(width1)
export(width2)
exportMethods("$")
exportMethods(end1)
exportMethods(end2)
exportMethods(seqnames1)
Expand Down Expand Up @@ -60,3 +62,4 @@ importFrom(rlang,quo_name)
importFrom(rlang,quos)
importFrom(tibble,as_tibble)
importFrom(tidyselect,eval_select)
importFrom(utils,.DollarNames)
19 changes: 18 additions & 1 deletion R/ginteractions-getters.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
#'
#' @name ginteractions-getters
#' @param x a GInteractions object
#' @param pattern,name The pattern or name of a column stored in
#' the GInteractions metadata (mcols).
#' @return One of the core GInteractions fields (e.g. seqnames1, start1, ...)
#' or one of the metadata columns when using `$`.
#' Note that auto-completion works with `$`.
#' @examples
#' gi <- data.frame(
#' seqnames1 = 'chr1', start1 = 1, end1 = 10,
#' seqnames2 = 'chr1', start2 = 1, end2 = 10
#' ) |> as_ginteractions()
#' ) |> as_ginteractions() |> mutate(type = 'cis')
#' seqnames1(gi)
#' seqnames2(gi)
#' start1(gi)
Expand All @@ -18,8 +22,21 @@
#' width2(gi)
#' strand1(gi)
#' strand2(gi)
#' gi$type
NULL

#' @rdname ginteractions-getters
#' @importFrom utils .DollarNames
#' @export
.DollarNames.GInteractions <- function(x, pattern = "")
grep(pattern, names(mcols(x, use.names = FALSE)), value = TRUE)

#' @rdname ginteractions-getters
#' @export
setMethod("$", "GInteractions",
function(x, name) mcols(x, use.names=FALSE)[[name]]
)

#' @rdname ginteractions-getters
#' @export
setGeneric("seqnames1", function(x) standardGeneric("seqnames1"))
Expand Down
14 changes: 13 additions & 1 deletion man/ginteractions-getters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 207a5d8

Please sign in to comment.