From ed441adf6a79463855da2e96f3472f555f813c2a Mon Sep 17 00:00:00 2001 From: Thomas Hackl Date: Mon, 1 Feb 2021 23:59:25 +0100 Subject: [PATCH] tag internals and clean up function reference some more, resolves #25 --- NAMESPACE | 5 ----- R/aaa.R | 1 + R/activate.R | 24 ------------------------ R/coords.R | 4 +++- R/feats.R | 2 ++ R/gggenomes.R | 8 +++++--- R/links.R | 2 ++ R/pull_tracks.R | 4 +++- R/seqs.R | 3 +++ R/subfeats.R | 1 + R/sublinks.R | 1 + R/tracks.R | 1 + R/vars.R | 6 ++++-- _pkgdown.yml | 32 +++++++------------------------- man/activate.Rd | 14 -------------- man/anchor.Rd | 1 + man/as_feats.Rd | 1 + man/as_links.Rd | 1 + man/as_seqs.Rd | 1 + man/as_subfeats.Rd | 1 + man/as_sublinks.Rd | 1 + man/as_tracks.Rd | 1 + man/comma.Rd | 1 + man/dim.gggenomes_layout.Rd | 1 + man/get_seqs.Rd | 3 +++ man/ggplot.gggenomes_layout.Rd | 1 + man/has_vars.Rd | 1 + man/layout_feats.Rd | 1 + man/layout_links.Rd | 1 + man/match_arg.Rd | 1 + man/vars_track.Rd | 2 ++ man/vars_track_error.Rd | 5 +++-- man/x.Rd | 4 +--- 33 files changed, 56 insertions(+), 80 deletions(-) delete mode 100644 R/activate.R delete mode 100644 man/activate.Rd diff --git a/NAMESPACE b/NAMESPACE index 0b749477..98bb3671 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,5 @@ # Generated by roxygen2: do not edit by hand -S3method(activate,tbl_genome_layout) S3method(add_clusters,gggenomes) S3method(add_clusters,gggenomes_layout) S3method(add_feats,gggenomes) @@ -81,8 +80,6 @@ export(PositionPile) export(PositionSixframe) export(PositionStrand) export(PositionStrandpile) -export(activate) -export(active) export(add_clusters) export(add_feats) export(add_links) @@ -190,7 +187,5 @@ importFrom(jsonlite,fromJSON) importFrom(magrittr,"%<>%") importFrom(magrittr,"%>%") importFrom(readr,read_tsv) -importFrom(rlang,enquo) -importFrom(rlang,quo_text) importFrom(tidyr,unnest) importFrom(tidyr,unnest_wider) diff --git a/R/aaa.R b/R/aaa.R index ced0325c..0e119f49 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -24,6 +24,7 @@ swap_if <- function(x, condition, ...){ #' #' @param x vector (coerced to character) #' @param collapse character string to separate elements. +#' @keywords internal comma <- function(x, collapse = ","){ paste(x, collapse=collapse) } diff --git a/R/activate.R b/R/activate.R deleted file mode 100644 index 56106897..00000000 --- a/R/activate.R +++ /dev/null @@ -1,24 +0,0 @@ -#' activate -#' -#' @export -activate <- function(data, what) { - UseMethod('activate') -} -#' @export -#' @importFrom rlang enquo quo_text -activate.tbl_genome_layout <- function(data, what) { - active(data) <- quo_text(enquo(what)) - data -} - -#' @rdname activate -#' @export -active <- function(data) { - attr(data, 'active') -} -`active<-` <- function(data, value) { - value <- gsub('"', '', value) - if(is.null(data[[value]])) stop('Unknown data set ', value, call. = FALSE); - attr(data, 'active') <- value - data -} diff --git a/R/coords.R b/R/coords.R index d0071290..ddb1fb27 100644 --- a/R/coords.R +++ b/R/coords.R @@ -1,6 +1,7 @@ #' The virtual x-start of the full length seq in the plot #' #' Together with the seq strand, this is sufficient to project feats +#' @keywords internal anchor <- function(x, start, strand){ x - (start-1) * strand_int(strand) } @@ -9,13 +10,14 @@ anchor <- function(x, start, strand){ #' #' @param seq_anchor the virtual x-start of the full length sequence in plot #' space +#' @keywords internal x <- function(start, end, strand, seq_x, seq_start, seq_strand){ a <- anchor(seq_x, seq_start, seq_strand) b <- if_reverse(strand, end, start-1) a + b * strand_int(seq_strand) } -#' @rdname x +#' @keywords internal xend <- function(start, end, strand, seq_x, seq_start, seq_strand){ a <- anchor(seq_x, seq_start, seq_strand) b <- if_reverse(strand, start-1, end)#, end + width(start,end)) diff --git a/R/feats.R b/R/feats.R index 7549d86c..74829744 100644 --- a/R/feats.R +++ b/R/feats.R @@ -18,6 +18,7 @@ #' @param ... passed on to `layout_seqs()` #' @return a tbl_df with plot coordinates #' @export +#' @keywords internal as_feats <- function(x, seqs, ..., everything=TRUE){ UseMethod("as_feats") } @@ -66,6 +67,7 @@ as_feats.tbl_df <- function(x, seqs, ..., everything=TRUE){ #' example after focusing in on a subregion. Choices are to "drop" them, "keep" #' them or "trim" them to the subregion boundaries. #' @param ... not used +#' @keywords internal layout_feats <- function(x, seqs, keep="strand", marginal=c("trim", "drop", "keep"), ...){ marginal <- match.arg(marginal) diff --git a/R/gggenomes.R b/R/gggenomes.R index ee72469f..0b94c9ae 100644 --- a/R/gggenomes.R +++ b/R/gggenomes.R @@ -90,6 +90,7 @@ gggenomes <- function(seqs=NULL, genes=NULL, feats=NULL, links=NULL, ..., #' ggplot.default tries to `fortify(data)` and we don't want that here #' #' @export +#' @keywords internal ggplot.gggenomes_layout <- function(data, mapping = aes(), ..., environment = parent.frame()) { if (!missing(mapping) && !inherits(mapping, "uneval")) { @@ -134,15 +135,15 @@ layout_genomes <- function(seqs=NULL, genes=NULL, feats=NULL, links=NULL, seqs <- mutate(seqs, bin_id = {{ infer_bin_id }}) }else{ if(is.null(feats) & is.null(links)) - stop("Need at least one of: seqs, genes, feats or links") + abort("Need at least one of: seqs, genes, feats or links") # infer dummy seqs if(!is.null(feats)){ - write("No seqs provided, inferring seqs from feats", stderr()) + inform("No seqs provided, inferring seqs from feats") seqs <- infer_seqs_from_feats(feats[[1]], {{infer_bin_id}}, {{infer_start}}, {{infer_end}}, {{infer_length}}) }else if(!is.null(links)){ - write("No seqs or feats provided, inferring seqs from links", stderr()) + inform("No seqs or feats provided, inferring seqs from links") seqs <- infer_seqs_from_links(links[[1]], {{infer_bin_id}}, {{infer_start}}, {{infer_end}}, {{infer_length}}) } @@ -165,6 +166,7 @@ layout_genomes <- function(seqs=NULL, genes=NULL, feats=NULL, links=NULL, #' and error because dim(gggenome_layout) is undefined. Return dim of primary #' table instead #' @export +#' @keywords internal dim.gggenomes_layout <- function(x) dim(get_seqs(x)) #' @export diff --git a/R/links.R b/R/links.R index 045936e3..0b522c22 100644 --- a/R/links.R +++ b/R/links.R @@ -17,6 +17,7 @@ #' @param x link data convertible to a link layout #' @inheritParams as_feats #' @export +#' @keywords internal as_links <- function(x, seqs, ..., everything=TRUE){ UseMethod("as_links") } @@ -64,6 +65,7 @@ as_links.tbl_df <- function(x, seqs, ..., everything=TRUE){ #' #' @inheritParams as_links #' @param ... not used +#' @keywords internal layout_links <- function(x, seqs, keep="strand", adjacent_only = TRUE, marginal=c("trim", "drop", "keep"), ...){ marginal <- match.arg(marginal) diff --git a/R/pull_tracks.R b/R/pull_tracks.R index 1a5727f8..e787d2cd 100644 --- a/R/pull_tracks.R +++ b/R/pull_tracks.R @@ -213,6 +213,7 @@ pull_track.gggenomes_layout <- function(.x, .track_id=1, ..., .track_type=NULL, #' giving the position from the left/right. #' @param track_type restrict to these types of tracks - affects position-based #' selection +#' @param ignore_pos names of tracks to ignore when selecting by position. #' @return The selected track_id as an unnamed string vars_track <- function(x, track_id, track_type = c("seqs", "feats", "links"), ignore_pos = NULL){ @@ -246,7 +247,8 @@ vars_track <- function(x, track_id, track_type = c("seqs", "feats", "links"), }) } -#' Error messages for `vars_track`` +#' Error messages for vars_track +#' @keywords internal vars_track_error <- function(bad_value, track_ids, ignore_pos){ if(is_function(bad_value)) bad_value <- "" if(is.numeric(bad_value)) bad_value <- as.character(bad_value) diff --git a/R/seqs.R b/R/seqs.R index 629ca429..bd1dafb8 100644 --- a/R/seqs.R +++ b/R/seqs.R @@ -17,6 +17,7 @@ #' #' as_seqs(chr) #' @export +#' @keywords internal as_seqs <- function(x, ...){ UseMethod("as_seqs") } @@ -164,6 +165,8 @@ get_seqs.gggenomes <- function(x){ get_seqs.gggenomes_layout <- function(x){ x$seqs[["seqs"]] } + +#' @rdname get_seqs #' @export set_seqs <- function(x, value){ UseMethod("set_seqs") diff --git a/R/subfeats.R b/R/subfeats.R index 01c84f00..b2f99b2e 100644 --- a/R/subfeats.R +++ b/R/subfeats.R @@ -73,6 +73,7 @@ add_subfeat_tracks <- function(x, parent_track_id, tracks, transform){ #' annotations, e.g. genes and protein blast results. #' @return a tbl_df with plot coordinates #' @export +#' @keywords internal as_subfeats <- function(x, seqs, feats, ..., everything=TRUE){ UseMethod("as_subfeats") } diff --git a/R/sublinks.R b/R/sublinks.R index c2505c43..ef7e3756 100644 --- a/R/sublinks.R +++ b/R/sublinks.R @@ -69,6 +69,7 @@ add_sublink_tracks <- function(x, parent_track_id, tracks, transform){ #' annotations, e.g. genes and protein blast results. #' @return a tbl_df with plot coordinates #' @export +#' @keywords internal as_sublinks <- function(x, seqs, feats, ..., everything=TRUE){ UseMethod("as_sublinks") } diff --git a/R/tracks.R b/R/tracks.R index 19526276..6bacda76 100644 --- a/R/tracks.R +++ b/R/tracks.R @@ -84,6 +84,7 @@ tracks.gggenomes_layout <- function(x, track_type = c("seqs", "feats", "links")) #' Convert a list of tibbles into tracks with magic +#' @keywords internal as_tracks <- function(tracks, tracks_exprs, reserved_ids=NULL){ # capture for df naming before first eval of tracks track_name <- as_label(enexpr(tracks)) diff --git a/R/vars.R b/R/vars.R index c31f5c0c..07c3b0f9 100644 --- a/R/vars.R +++ b/R/vars.R @@ -29,9 +29,9 @@ require_vars <- function(x, vars, warn_only=FALSE){ if(length(missing_vars) > 0) if(warn_only) - warning("Required column(s) missing: ", paste(missing_vars, collapse=",")) + warn(c("Required column(s) missing: ", str_glue("{missing_vars}"))) else - stop("Required column(s) missing: ", paste(missing_vars, collapse=",")) + abort(c("Required column(s) missing: ", str_glue("{missing_vars}"))) x } @@ -45,6 +45,7 @@ require_vars <- function(x, vars, warn_only=FALSE){ #' @param any if TRUE not all but at least one variable has to exists #' @return TRUE/FALSE #' @export +#' @keywords internal has_vars <- function(x, vars, any=FALSE){ if(any) any(vars %in% names(x)) @@ -56,6 +57,7 @@ has_vars <- function(x, vars, any=FALSE){ #' #' equivalent to base::match.arg, but returns all choices on arg=NULL if #' several.ok=TRUE +#' @keywords internal match_arg <- function (arg, choices, several.ok = FALSE){ if (missing(choices)) { formal.args <- formals(sys.function(sysP <- sys.parent())) diff --git a/_pkgdown.yml b/_pkgdown.yml index c646a280..dfa22a09 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -15,10 +15,10 @@ reference: - geom_gene - geom_feat - geom_link - - ends_with(c("_text", "_tag", "_note")) + - ends_with("_text|_tag|_note") - starts_with("geom") - starts_with("position_") - - starts_with("use_") + - starts_with("theme_") - title: "Manipulate plot & data" - contents: - pick @@ -37,37 +37,21 @@ reference: - file_formats - def_names - def_types + - starts_with("write") - title: "Under the hood" desc: > Functions that power gggenomes under the hood. Useful for developers and power-users. - contents: - layout - - layout_feats - - layout_links - - require_vars - get_seqs - - starts_with("as_") + - starts_with("track") + - require_vars + - vars_track - swap_if - in_range - - anchor - width - - x - - track_ids - - track_types - - vars_track - - activate - - comma - - dim.gggenomes_layout - - ggplot.gggenomes_layout - - has_vars - introduce - - match_arg - - theme_gggenomes_clean - - track_nrows - - track_type - - vars_track_error - - write_gff3 -- title: "Handling files" +- title: "Handle files" - contents: - ext_to_format - file_exts @@ -78,8 +62,6 @@ reference: figures: fig.width: 10 fig.height: 5 - # dev.args: - # type: "cairo" template: params: bootswatch: cosmo diff --git a/man/activate.Rd b/man/activate.Rd deleted file mode 100644 index 2a7274d7..00000000 --- a/man/activate.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/activate.R -\name{activate} -\alias{activate} -\alias{active} -\title{activate} -\usage{ -activate(data, what) - -active(data) -} -\description{ -activate -} diff --git a/man/anchor.Rd b/man/anchor.Rd index b22f345e..b4f5abfc 100644 --- a/man/anchor.Rd +++ b/man/anchor.Rd @@ -9,3 +9,4 @@ anchor(x, start, strand) \description{ Together with the seq strand, this is sufficient to project feats } +\keyword{internal} diff --git a/man/as_feats.Rd b/man/as_feats.Rd index c7260e75..7dc127cb 100644 --- a/man/as_feats.Rd +++ b/man/as_feats.Rd @@ -31,3 +31,4 @@ records that initially had \code{start < end} and "-" for \code{end < start} inp \code{strand} was provided, \code{start} and \code{end} will be ordered without any additional effect. } +\keyword{internal} diff --git a/man/as_links.Rd b/man/as_links.Rd index 6097d819..c1d875e9 100644 --- a/man/as_links.Rd +++ b/man/as_links.Rd @@ -31,3 +31,4 @@ ggplots native transformation functions for position aesthetics. Those only work well with a specific set of predefined var names, which include those used above. } +\keyword{internal} diff --git a/man/as_seqs.Rd b/man/as_seqs.Rd index 5e937ed1..23a6a8ab 100644 --- a/man/as_seqs.Rd +++ b/man/as_seqs.Rd @@ -31,3 +31,4 @@ chr <- tibble( as_seqs(chr) } +\keyword{internal} diff --git a/man/as_subfeats.Rd b/man/as_subfeats.Rd index 16f5bda5..3f99e471 100644 --- a/man/as_subfeats.Rd +++ b/man/as_subfeats.Rd @@ -41,3 +41,4 @@ records that initially had \code{start < end} and "-" for \code{end < start} inp \code{strand} was provided, \code{start} and \code{end} will be reorganized to conform with \code{start < end} without any additional effect. } +\keyword{internal} diff --git a/man/as_sublinks.Rd b/man/as_sublinks.Rd index f4c86437..1da6b42f 100644 --- a/man/as_sublinks.Rd +++ b/man/as_sublinks.Rd @@ -40,3 +40,4 @@ records that initially had \verb{start < end == start2 < end2} and "-" otherwise. If \code{strand} was provided, \code{start} and \code{end} will be reorganized to conform with \code{start < end} without any additional effect. } +\keyword{internal} diff --git a/man/as_tracks.Rd b/man/as_tracks.Rd index f1fd8450..07683d85 100644 --- a/man/as_tracks.Rd +++ b/man/as_tracks.Rd @@ -9,3 +9,4 @@ as_tracks(tracks, tracks_exprs, reserved_ids = NULL) \description{ Convert a list of tibbles into tracks with magic } +\keyword{internal} diff --git a/man/comma.Rd b/man/comma.Rd index e10ff05a..0c9d0f25 100644 --- a/man/comma.Rd +++ b/man/comma.Rd @@ -14,3 +14,4 @@ comma(x, collapse = ",") \description{ Collapse a string with commas } +\keyword{internal} diff --git a/man/dim.gggenomes_layout.Rd b/man/dim.gggenomes_layout.Rd index 3c91060f..f5daa225 100644 --- a/man/dim.gggenomes_layout.Rd +++ b/man/dim.gggenomes_layout.Rd @@ -13,3 +13,4 @@ table instead} and error because dim(gggenome_layout) is undefined. Return dim of primary table instead } +\keyword{internal} diff --git a/man/get_seqs.Rd b/man/get_seqs.Rd index fdedcaff..59171c5a 100644 --- a/man/get_seqs.Rd +++ b/man/get_seqs.Rd @@ -2,9 +2,12 @@ % Please edit documentation in R/seqs.R \name{get_seqs} \alias{get_seqs} +\alias{set_seqs} \title{Get/set the seqs track} \usage{ get_seqs(x) + +set_seqs(x, value) } \arguments{ \item{x}{a gggenomes or gggenomes_layout objekt} diff --git a/man/ggplot.gggenomes_layout.Rd b/man/ggplot.gggenomes_layout.Rd index 94e59581..e90b7f29 100644 --- a/man/ggplot.gggenomes_layout.Rd +++ b/man/ggplot.gggenomes_layout.Rd @@ -9,3 +9,4 @@ \description{ ggplot.default tries to \code{fortify(data)} and we don't want that here } +\keyword{internal} diff --git a/man/has_vars.Rd b/man/has_vars.Rd index 60a28157..39fedaaf 100644 --- a/man/has_vars.Rd +++ b/man/has_vars.Rd @@ -20,3 +20,4 @@ TRUE/FALSE Returns TRUE if all variables exists. If \code{any=TRUE} returns TRUE if at least one variable exists. } +\keyword{internal} diff --git a/man/layout_feats.Rd b/man/layout_feats.Rd index 0bd3da46..38e659b2 100644 --- a/man/layout_feats.Rd +++ b/man/layout_feats.Rd @@ -26,3 +26,4 @@ them or "trim" them to the subregion boundaries.} \description{ Augment feats with all data necessary for plotting } +\keyword{internal} diff --git a/man/layout_links.Rd b/man/layout_links.Rd index 662e1941..8c97b3e5 100644 --- a/man/layout_links.Rd +++ b/man/layout_links.Rd @@ -23,3 +23,4 @@ layout_links( \description{ Layout tbl_link } +\keyword{internal} diff --git a/man/match_arg.Rd b/man/match_arg.Rd index 0ea26a50..d0ac3b6e 100644 --- a/man/match_arg.Rd +++ b/man/match_arg.Rd @@ -10,3 +10,4 @@ match_arg(arg, choices, several.ok = FALSE) equivalent to base::match.arg, but returns all choices on arg=NULL if several.ok=TRUE } +\keyword{internal} diff --git a/man/vars_track.Rd b/man/vars_track.Rd index 3f308fe5..19194f62 100644 --- a/man/vars_track.Rd +++ b/man/vars_track.Rd @@ -19,6 +19,8 @@ giving the position from the left/right.} \item{track_type}{restrict to these types of tracks - affects position-based selection} + +\item{ignore_pos}{names of tracks to ignore when selecting by position.} } \value{ The selected track_id as an unnamed string diff --git a/man/vars_track_error.Rd b/man/vars_track_error.Rd index 7310c5cb..a9d42247 100644 --- a/man/vars_track_error.Rd +++ b/man/vars_track_error.Rd @@ -2,10 +2,11 @@ % Please edit documentation in R/pull_tracks.R \name{vars_track_error} \alias{vars_track_error} -\title{Error messages for `vars_track``} +\title{Error messages for vars_track} \usage{ vars_track_error(bad_value, track_ids, ignore_pos) } \description{ -Error messages for `vars_track`` +Error messages for vars_track } +\keyword{internal} diff --git a/man/x.Rd b/man/x.Rd index 89aa6588..1c20501f 100644 --- a/man/x.Rd +++ b/man/x.Rd @@ -2,12 +2,9 @@ % Please edit documentation in R/coords.R \name{x} \alias{x} -\alias{xend} \title{Project feat coordinates into layout space} \usage{ x(start, end, strand, seq_x, seq_start, seq_strand) - -xend(start, end, strand, seq_x, seq_start, seq_strand) } \arguments{ \item{seq_anchor}{the virtual x-start of the full length sequence in plot @@ -16,3 +13,4 @@ space} \description{ Project feat coordinates into layout space } +\keyword{internal}