Skip to content

Commit 3053ec6

Browse files
added examples
1 parent 6e79964 commit 3053ec6

20 files changed

+199
-15
lines changed

R/taxmap--arrange.R

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
#' \link[dplyr]{arrange} for more details.
66
#'
77
#' @param .data \code{\link{taxmap}}
8-
#' @param ... One or more column names to sort on. Newly created columns can be referenced in the
9-
#' same function call.
8+
#' @param ... One or more column names to sort on.
109
#'
1110
#' @return An object of type \code{\link{taxmap}}
1211
#'
1312
#' @family dplyr-like functions
13+
#'
14+
#' @examples
15+
#' # Sort by taxon name alphabetically
16+
#' arrange_taxa(unite_ex_data_3, name)
17+
#' # Reverse order of sort
18+
#' arrange_taxa(unite_ex_data_3, desc(name))
1419
#'
1520
#' @export
1621
arrange_taxa <- function(.data, ...) {
@@ -29,13 +34,18 @@ arrange_taxa <- function(.data, ...) {
2934
#' \link[dplyr]{arrange} for more details.
3035
#'
3136
#' @param .data \code{\link{taxmap}}
32-
#' @param ... One or more column names to sort on. Newly created columns can be referenced in the
33-
#' same function call.
37+
#' @param ... One or more column names to sort on.
3438
#'
3539
#' @return An object of type \code{\link{taxmap}}
3640
#'
3741
#' @family dplyr-like functions
3842
#'
43+
#' @examples
44+
#' # Sort observations by sequence name alphabetically
45+
#' arrange_obs(unite_ex_data_3, seq_name)
46+
#' # Reverse order of sort
47+
#' arrange_obs(unite_ex_data_3, desc(seq_name))
48+
#'
3949
#' @export
4050
arrange_obs <- function(.data, ...) {
4151
my_obs_data <- obs_data(.data, col_subset = obs_data_cols_used(.data, ...))

R/taxmap--filter.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@
3131
#' @return An object of type \code{\link{taxmap}}
3232
#'
3333
#' @family dplyr-like functions
34-
#'
34+
#'
35+
#' @examples
36+
#' # Remove singleton taxa, but reassign singletons to supertaxa that pass filter
37+
#' filter_taxa(unite_ex_data_3, n_obs > 1)
38+
#' # Remove singleton taxa and associated seqeuence data
39+
#' filter_taxa(unite_ex_data_3, n_obs > 1, taxonless = FALSE, reassign_obs = FALSE)
40+
#' # Subset to a single taxon and its subtaxa
41+
#' filter_taxa(unite_ex_data_3, name == "Basidiomycota", subtaxa = TRUE)
42+
#' # Remove a taxon and its subtaxa
43+
#' filter_taxa(unite_ex_data_3, name == "Basidiomycota", subtaxa = TRUE, invert = TRUE)
44+
#' # Remove taxa, reassigning supertaxa and subtaxa
45+
#' filter_taxa(unite_ex_data_3, unite_rank != "p")
46+
#'
3547
#' @export
3648
filter_taxa <- function(.data, ..., subtaxa = FALSE, supertaxa = FALSE, taxonless = FALSE,
3749
reassign_obs = TRUE, reassign_taxa = TRUE, invert = FALSE) {
@@ -134,7 +146,13 @@ filter_taxa <- function(.data, ..., subtaxa = FALSE, supertaxa = FALSE, taxonles
134146
#' @return An object of type \code{\link{taxmap}}
135147
#'
136148
#' @family dplyr-like functions
137-
#'
149+
#'
150+
#' @examples
151+
#' # Filter by sequence name, but preserve all taxa
152+
#' filter_obs(unite_ex_data_3, grepl("Lachnum", seq_name))
153+
#' # Filter by sequence name and only keep taxa with sequences that pass the filter
154+
#' filter_obs(unite_ex_data_3, grepl("Lachnum", seq_name), unobserved = FALSE)
155+
#'
138156
#' @export
139157
filter_obs <- function(.data, ..., unobserved = TRUE) {
140158
# non-standard argument evaluation ---------------------------------------------------------------

R/taxmap--mutate.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#' @return An object of type \code{\link{taxmap}}
1212
#'
1313
#' @family dplyr-like functions
14-
#'
14+
#'
15+
#' @examples
16+
#' # Add one or more taxon columns
17+
#' mutate_taxa(unite_ex_data_3, x = 1, y = x+2)
18+
#'
1519
#' @export
1620
mutate_taxa <- function(.data, ...) {
1721
data_used <- taxon_data(.data, col_subset = taxon_data_cols_used(.data, ...))
@@ -39,6 +43,10 @@ mutate_taxa <- function(.data, ...) {
3943
#' @return An object of type \code{\link{taxmap}}
4044
#'
4145
#' @family dplyr-like functions
46+
#'
47+
#' @examples
48+
#' # Add one or more observation columns
49+
#' mutate_obs(unite_ex_data_3, x = 1, y = x+2)
4250
#'
4351
#' @export
4452
mutate_obs <- function(.data, ...) {
@@ -66,6 +74,10 @@ mutate_obs <- function(.data, ...) {
6674
#' @return An object of type \code{\link{taxmap}}
6775
#'
6876
#' @family dplyr-like functions
77+
#'
78+
#' @examples
79+
#' # Replace all taxon columns with new columns
80+
#' transmute_taxa(unite_ex_data_3, x = 1, y = x+2)
6981
#'
7082
#' @export
7183
transmute_taxa <- function(.data, ...) {
@@ -94,6 +106,10 @@ transmute_taxa <- function(.data, ...) {
94106
#' @return An object of type \code{\link{taxmap}}
95107
#'
96108
#' @family dplyr-like functions
109+
#'
110+
#' @examples
111+
#' # Replace all observation columns with new columns
112+
#' transmute_obs(unite_ex_data_3, x = 1, y = x+2)
97113
#'
98114
#' @export
99115
transmute_obs <- function(.data, ...) {

R/taxmap--sample.R

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
#' @return An object of type \code{\link{taxmap}}
3232
#'
3333
#' @family dplyr-like functions
34+
#'
35+
#' @examples
36+
#' # Subsample without replacement, keeping all taxa
37+
#' sample_n_obs(unite_ex_data_3, 100)
38+
#' # Subsample without replacement and remove unsampled taxa
39+
#' sample_n_obs(unite_ex_data_3, 100, unobserved = FALSE)
40+
#' # Subsample with taxon weight
41+
#' sample_n_obs(unite_ex_data_3, 100, unobserved = FALSE, taxon_weight = 1 / n_obs)
42+
#' # Sample with replacement
43+
#' sample_n_obs(unite_ex_data_3, 10000, replace = TRUE)
3444
#'
3545
#' @export
3646
sample_n_obs <- function(.data, size, replace = FALSE, taxon_weight = NULL, obs_weight = NULL,
@@ -80,6 +90,17 @@ sample_n_obs <- function(.data, size, replace = FALSE, taxon_weight = NULL, obs_
8090
#'
8191
#' @family dplyr-like functions
8292
#'
93+
#'
94+
#' @examples
95+
#' # Subsample without replacement, keeping all taxa
96+
#' sample_frac_obs(unite_ex_data_3, 0.1)
97+
#' # Subsample without replacement and remove unsampled taxa
98+
#' sample_frac_obs(unite_ex_data_3, 0.1, unobserved = FALSE)
99+
#' # Subsample with taxon weight
100+
#' sample_frac_obs(unite_ex_data_3, 0.1, unobserved = FALSE, taxon_weight = 1 / n_obs)
101+
#' # Sample with replacement
102+
#' sample_frac_obs(unite_ex_data_3, 10, replace = TRUE)
103+
#'
83104
#' @export
84105
sample_frac_obs <- function(.data, size = 1, replace = FALSE, taxon_weight = NULL, obs_weight = NULL,
85106
use_supertaxa = TRUE, collapse_func = mean, ...) {
@@ -121,7 +142,14 @@ sample_frac_obs <- function(.data, size = 1, replace = FALSE, taxon_weight = NUL
121142
#' @return An object of type \code{\link{taxmap}}
122143
#'
123144
#' @family dplyr-like functions
124-
#'
145+
#'
146+
#' @examples
147+
#' # subsample taxa, preserving shared supertaxa
148+
#' sample_n_taxa(unite_ex_data_3, 100, supertaxa = TRUE)
149+
#' # subsample taxa using weights, preserving subtaxa
150+
#' sample_n_taxa(unite_ex_data_3, 10, subtaxa = TRUE,
151+
#' taxon_weight = ifelse(unite_rank == "g" & n_subtaxa > 3, 1, 0))
152+
#'
125153
#' @export
126154
sample_n_taxa <- function(.data, size, taxon_weight = NULL, obs_weight = NULL,
127155
use_subtaxa = TRUE, collapse_func = mean, ...) {
@@ -168,6 +196,13 @@ sample_n_taxa <- function(.data, size, taxon_weight = NULL, obs_weight = NULL,
168196
#'
169197
#' @family dplyr-like functions
170198
#'
199+
#' @examples
200+
#' # subsample taxa, preserving shared supertaxa
201+
#' sample_frac_taxa(unite_ex_data_3, 0.1, supertaxa = TRUE)
202+
#' # subsample taxa using weights, preserving subtaxa
203+
#' sample_frac_taxa(unite_ex_data_3, 0.01, subtaxa = TRUE,
204+
#' taxon_weight = ifelse(unite_rank == "g" & n_subtaxa > 3, 1, 0))
205+
#'
171206
#' @export
172207
sample_frac_taxa <- function(.data, size = 1, taxon_weight = NULL, obs_weight = NULL,
173208
use_subtaxa = TRUE, collapse_func = mean, ...) {

R/taxmap--select.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#' @return An object of type \code{\link{taxmap}}
1616
#'
1717
#' @family dplyr-like functions
18+
#'
19+
#' @examples
20+
#' # subset taxon columns
21+
#' select_taxa(unite_ex_data_3, name)
1822
#'
1923
#' @export
2024
select_taxa <- function(.data, ...) {
@@ -41,6 +45,10 @@ select_taxa <- function(.data, ...) {
4145
#' @return An object of type \code{\link{taxmap}}
4246
#'
4347
#' @family dplyr-like functions
48+
#'
49+
#' @examples
50+
#' # subset observation columns
51+
#' select_obs(unite_ex_data_3, other_id, seq_id)
4452
#'
4553
#' @export
4654
select_obs <- function(.data, ...) {

man/arrange_obs.Rd

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/arrange_taxa.Rd

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/filter_obs.Rd

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/filter_taxa.Rd

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mutate_obs.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)