diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33835b4..f5557e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,7 @@ jobs: -m '📄 Render README.Rmd' || echo "No changes to commit" - name: Docs run: | - Rscript -e "devtools::build_site()" + Rscript -e "pkgdown::build_reference; devtools::build_site()" git add docs git commit \ --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" \ diff --git a/NAMESPACE b/NAMESPACE index be0b72b..588b83d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,9 +2,11 @@ export("%>%") export(.data) +export(close_enough) export(format_number) export(inline_hook) export(is_nearly_whole) +export(is_nondesc) export(load_deps) export(paste_oxford_list) export(read_dist) diff --git a/NEWS.md b/NEWS.md index 5f807c2..a46fc74 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,10 +2,14 @@ - Added a `NEWS.md` file to track changes to the package. - Major new functions: - - `read_dist()` - - `read_tax()` - - `inline_hook()` - - `paste_oxford_list()` - - `format_number()` + - `read_dist()` (#10, @NLesniak) + - `read_tax()` (#22, @NLesniak) + - `set_knitr_opts()` (#21, @pschloss, @kelly-sovacool) + - `inline_hook()` (#21, @pschloss, @kelly-sovacool) + - `paste_oxford_list()` (#21, @pschloss, @kelly-sovacool) + - `format_number()` (#24, @pschloss, @kelly-sovacool) + - `is_nearly_whole()` (#24, @pschloss, @kelly-sovacool) + - `close_enough()` (#26, @kelly-sovacool) + - `is_nondesc()` (#28, @kelly-sovacool) - New vignettes: - `introduction` diff --git a/R/utils.R b/R/utils.R index eae7e3a..7c2cff0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -35,6 +35,31 @@ close_enough <- function(x, y, tol = 10^-3) { all(dplyr::near(x, y, tol = tol)) } +#' Check whether all elements given are sorted in non-descending order +#' +#' @param ... anything! +#' +#' @return `TRUE` if the elements are sorted in non-descending order, otherwise `FALSE` +#' @export +#' @author Kelly Sovacool \email{sovacool@@umich.edu} +#' +#' @examples +#' +#' is_nondesc(1, 2, 3) +#' is_nondesc(c(1, 2), 3) +#' is_nondesc(6, 4, 1) +#' is_nondesc("a", "b", "c") +#' is_nondesc(c("z", "y")) +is_nondesc <- function(...) { + things <- c(...) + if (length(things) < 1) { + warning("Zero elements were given to `is_nondesc()`") + } + first <- things[1] + last <- things[length(things)] + !is.unsorted(things) & first <= last +} + #' Install & load packages #' @param ... package names to install & load #' @export diff --git a/docs/CONTRIBUTING.html b/docs/CONTRIBUTING.html index ef934f9..df8d83a 100644 --- a/docs/CONTRIBUTING.html +++ b/docs/CONTRIBUTING.html @@ -136,9 +136,9 @@
Fork the package and clone onto your computer. If you haven’t done this before, we recommend using usethis::create_from_github("SchlossLab/mothuR", fork = TRUE)
.
Fork the package and clone onto your computer. If you haven’t done this before, we recommend using usethis::create_from_github("SchlossLab/mothuR", fork = TRUE)
.
Install all development dependences with devtools::install_dev_deps()
, and then make sure the package passes R CMD check by running devtools::check()
. If R CMD check doesn’t pass cleanly, it’s a good idea to ask for help before continuing.
Create a Git branch for your pull request (PR). We recommend using usethis::pr_init("brief-description-of-change")
.
Create a Git branch for your pull request (PR). We recommend using usethis::pr_init("brief-description-of-change")
.
Make your changes, commit to git, and then create a PR by running usethis::pr_push()
, and following the prompts in your browser. The title of your PR should briefly describe the change. The body of your PR should contain Fixes #issue-number
.
For user-facing changes, add a bullet to the top of NEWS.md
(i.e. just below the first header). Follow the style described in https://style.tidyverse.org/news.html.
DistCalc-package.Rd
More about what it does (maybe more than one line) -~~ A concise (1-5 lines) description of the package ~~
-Package: | DistCalc |
Type: | Package |
Version: | 1.0 |
Date: | 2012-12-14 |
License: | What license is it under? |
~~ An overview of how to use the package, including the most important functions ~~
-~~ Literature or other references for background information ~~
-~~ Optional links to other man pages, e.g. ~~
-~~ <pkg>
~~
-
PCoa3d.Rd
Plot the pcoa.axes output from mothur. Can accept a design file for groups.
-plotPCOA3d(file,design=FALSE,ax1=1, ax2=2, ax3=3, Lab1="Axis 1",Lab2="Axis 2", -Lab3="Axis 3", Pch = 19, Main = NULL, Sub=NULL, Scale.y=1, Angle=40, -Axis=TRUE, Tick.marks=TRUE, Label.tick.marks=TRUE, X.ticklabs=NULL, -Y.ticklabs=NULL, Z.ticklabs=NULL, Y.margin.add=0, Grid=TRUE, Box=TRUE, -Lab=par("lab"), Lab.z=mean(Lab[1:2]), Type="p", LX="topleft", LY= NULL)- -
file | -The .pcoa.axes file from mothur's pcoa function. |
-
---|---|
design | -The .design file for the groups you which to color the points by. defaults to no design file. |
-
ax1, ax2, ax3 | -The axes you wish to plot. Defaults to the 3 most relevant according to mothur. |
-
Lab1, Lab2, Lab3 | -titles for the 1st/x, 2nd/y and 3rd/z axis. |
-
Pch | -plotting "character", i.e. symbol to use. Defaults to 19 (solid circles) |
-
Main | -an overall title for the plot. |
-
Sub | -sub-title. |
-
Scale.y | -scale of y axis related to x- and z axis. |
-
Angle | -angle between x and y axis (Attention: result depends on scaling). |
-
Axis | -a logical value indicating whether axes should be drawn on the plot. |
-
Tick.marks | -a logical value indicating whether tick marks should be drawn on the plot (only if axis = TRUE). |
-
Label.tick.marks | -a logical value indicating whether tick marks should be labeled on the plot (only if axis = TRUE and tick.marks = TRUE). |
-
X.ticklabs, Y.ticklabs, Z.ticklabs | -vector of tick mark labels. |
-
Y.margin.add | -add additional space between tick mark labels and axis label of the y axis. |
-
Grid | -a logical value indicating whether a grid should be drawn on the plot. |
-
Box | -a logical value indicating whether a box should be drawn around the plot. |
-
Lab | -a numerical vector of the form c(x, y, len). The values of x and y give the (approximate) number of tickmarks on the x and y axes. |
-
Lab.z | -the same as lab, but for z axis. |
-
Type | -character indicating the type of plot: "p" for points, "l" for lines, "h" for vertical lines to x-y-plane, etc. |
-
LX, LY | -the x and y co-ordinates to be used to position the legend. They can be specified by keyword or in any way which is accepted by xy.coords. |
-
- - - -
-The mothuR page on mothur's wiki: http://www.mothur.org/wiki/mothuR
RarePlot.Rd
Plot the .group.rarefraction data which is the output from mothur's rarefraction.single function.
-rarePlot(file,groups,ylab= "Number of Different OTUs",xlab= "Number of Tags Sampled", - pch= NA, xlim = NULL, ylim = NULL, error=FALSE, delNum=6)- -
file | -The .group.rarefaction file which you wish to plot. Only works for the output of rarefaction.single from mothur. |
-
---|---|
groups | -The specific groups within x which you wish to plot, in list form c("Examplegroup1", "Examplegroup2'). either the names ie c("m24626d36", "Day3") or the number the group falls in the list of all groups. ie c(1,4,7) (the 1st 4th and 7th group). |
-
ylab | -Title for y axis. Defaults to "Number of Different OTUs" |
-
xlab | -Title for x axis. Defaults to "Number of Tags Sampled" |
-
pch | -Character string or vector of 1-characters or integers for plotting characters, see points. The first character is the plotting-character for the first plot, the second for the second, etc. The default is nothing. Change to NULL if you want the digits 1:9 then the lowercase and uppercase letters |
-
xlim | -Range of x axis |
-
ylim | -Range of y axis |
-
error | -If error = TRUE then plot the Lower and Upperbounds for each group. |
-
delNum | -The number of excess characters before each name generally X0.03. or something similiar. Set delNum to the number you which to delete. |
-
The Rarefaction function on mothur's wiki http://www.mothur.org/wiki/Rarefaction.single
,
-#> Error in RarePlot("example.groups.shared", c("Examplegroup1", "Examplegroup2", "ExampleGroup3")): could not find function "RarePlot"#> Error in RarePlot("example2.groups.shared", c(14, 11, 30, "ExampleGroup4"), error = TRUE, pch = NULL): could not find function "RarePlot"
between.dist.Rd
Imports a distance matrix and a '.design' file, and uses them to return statistics about the distances between defined groups of samples. Prints statistics and when asigned to a variable, returns a list of the distances between designated groups to be used for further analysis.
-between.dist(dist, design, groups, subgroups=FALSE)- -
dist | -Either a file containing a phylip formatted distance matrix with ThetaYC, UniFrac, or some other distance metric between samples or a variable representing the distance matrix that was imported using the read.dist function. |
-
---|---|
design | -a '.design' file, i.e. a file containing two columns separated by a tab, with the sample names in the left column and the name of their group in the right column. |
-
groups | -a vector of strings containing the names of the groups to be analyzed. There is no limit to the number of groups that can be analyzed. The parameter 'all' can be used to analyze the relationships between all groups. |
-
subgroups | -a logical value determing whether to use the group column or the subgroup column in the analysis (FALSE is groups TRUE is subgroups). (which subgroups to use are determined by the groups vector.) |
-
If the dist paramater is a phylip file, then the function will start by using the read.dist function to import the distance matrix. The function will then parse distance matrix into smaller matrices each containing the columns from one group of interest and the rows of another. The distances in each of the smaller matrices are then used to calculated the minimum, maximum, median, mean, and standard deviation of the distances between each group. The statistics are printed to the screen.
-When assigned to a variable, the function will output a list of vectors, each containing all of the distances between the two groups. The vectors in the list are named "'group1' vs 'group2', "'group1' vs 'group3, etc. This list output can used for further statistical analysis of the distances, such as a Wilcoxon test, or can be input in the plot.dists function to make a barplot of the distances.
-The function is designed such that each pair of groups is only compared once and the distances within a group are not returned. For distances within a group use the within.dist function.
-- - - -
-Since the output of this function is a list, pulling out a vector from the list is done using my.list[[1]]. To get a single distance assign my.list[[1]] to a variable (i.e. vect1<-my.list[[1]]) then specify the component of the list using vect1[1]. I only say this because it may not be obvious to people who aren't experienced R users.
-within.dist for calculating distances within groups -plot.dist for plotting the output from of between.dist and within.dist
-#Using a phylip file as input -#between.dist('~/Desktop/germfree.sq.dist','~/Desktop/germfree.design', c('early','late')) - -#Using a distance matrix that has already been read in using read.dist -#between.dist(gf.sq.dist,'~/Desktop/germfree.design', c('early','late')) - -#Calculating distances between combinations of groups -#between.dist('~/Desktop/germfree.sq.dist','~/Desktop/germfree.design', 'all') - -#Plotting the output -#btwn.list<-between.dist('~/Desktop/germfree.sq.dist','~/Desktop/germfree.design', c('early','late')) -#plot.dists(btwn.list) - - -## The function is currently defined as -function (dist, design, groups) -{ - if (length(groups) == 1) { - options(warn = (-1)) - if (groups == "all") { - if (length(design) == 1) { - dsn <- read.table(design) - } - if (length(design) > 1) { - dsn <- design - } - groups <- as.vector(unique(dsn[, 2])) - options(warn = (0)) - } - } - one.between <- function(dist, design, group1, group2) { - if (typeof(dist) == "character") { - dist <- read.dist(dist) - } - if (length(design) == 1) { - design <- read.design(design) - } - get.dists <- function(dist, Detailsdesign, group1, group2) { - group1 <<- group1 - group2 <<- group2 - get.grp1 <- function(d, g) { - c1 <- 1 - grp1 <- c() - for (i in 1:nrow(d)) { - if (d[i, 2] == g) { - grp1[c1] <- d[i, 1] - c1 <- c1 + 1 - } - } - invisible(grp1) - } - get.grp2 <- function(d, g) { - c2 <- 1 - grp2 <- c() - for (i in 1:nrow(d)) { - if (d[i, 2] == g) { - grp2[c2] <- d[i, 1] - c2 <- c2 + 1 - } - } - invisible(grp2) - } - grp1 <- get.grp1(design, group1) - grp2 <- get.grp2(design, group2) - get.rows <- function(dist, grp) { - rows <- dist[grp[1], ] - for (i in 2:length(grp)) { - rows <- rbind(rows, dist[grp[i], ]) - } - invisible(rows) - } - rows <- get.rows(dist, grp1) - get.rows <- function(dist, grp) { - matrix <- dist[, grp[1]] - for (i in 2:length(grp)) { - matrix <- cbind(matrix, dist[, grp[i]]) - } - invisible(matrix) - } - matrix <- get.rows(rows, grp2) - vect <- as.vector(matrix) - invisible(vect) - } - dists <- get.dists(dist, design, group1, group2) - cat(sprintf("Stats for distances between %s and %s", - group1, group2), "\n", sprintf("Minimum: %f", min(dists)), - "\n", sprintf("Maximum: %f", max(dists)), "\n", sprintf("Median: %f", - median(dists)), "\n", sprintf("Mean: %f", mean(dists)), - "\n", sprintf("Std. Dev.: %f", sd(dists)), "\n", - "\n", sep = "") - return(dists) - } - dist.vect <- c() - c <- 1 - dist.list <- vector(mode = "list", length = ((length(groups)^2 - - length(groups))/2)) - list.names <- c() - for (i in 1:(length(groups) - 1)) { - for (j in (i + 1):length(groups)) { - list.names[c] <- paste(groups[i], "vs", groups[j]) - dist.list[[c]] <- one.between(dist, design, groups[i], - groups[j]) - c <- c + 1 - } - } - names(dist.list) <- list.names - invisible(dist.list) - }#> function (dist, design, groups) -#> { -#> if (length(groups) == 1) { -#> options(warn = (-1)) -#> if (groups == "all") { -#> if (length(design) == 1) { -#> dsn <- read.table(design) -#> } -#> if (length(design) > 1) { -#> dsn <- design -#> } -#> groups <- as.vector(unique(dsn[, 2])) -#> options(warn = (0)) -#> } -#> } -#> one.between <- function(dist, design, group1, group2) { -#> if (typeof(dist) == "character") { -#> dist <- read.dist(dist) -#> } -#> if (length(design) == 1) { -#> design <- read.design(design) -#> } -#> get.dists <- function(dist, Detailsdesign, group1, group2) { -#> group1 <<- group1 -#> group2 <<- group2 -#> get.grp1 <- function(d, g) { -#> c1 <- 1 -#> grp1 <- c() -#> for (i in 1:nrow(d)) { -#> if (d[i, 2] == g) { -#> grp1[c1] <- d[i, 1] -#> c1 <- c1 + 1 -#> } -#> } -#> invisible(grp1) -#> } -#> get.grp2 <- function(d, g) { -#> c2 <- 1 -#> grp2 <- c() -#> for (i in 1:nrow(d)) { -#> if (d[i, 2] == g) { -#> grp2[c2] <- d[i, 1] -#> c2 <- c2 + 1 -#> } -#> } -#> invisible(grp2) -#> } -#> grp1 <- get.grp1(design, group1) -#> grp2 <- get.grp2(design, group2) -#> get.rows <- function(dist, grp) { -#> rows <- dist[grp[1], ] -#> for (i in 2:length(grp)) { -#> rows <- rbind(rows, dist[grp[i], ]) -#> } -#> invisible(rows) -#> } -#> rows <- get.rows(dist, grp1) -#> get.rows <- function(dist, grp) { -#> matrix <- dist[, grp[1]] -#> for (i in 2:length(grp)) { -#> matrix <- cbind(matrix, dist[, grp[i]]) -#> } -#> invisible(matrix) -#> } -#> matrix <- get.rows(rows, grp2) -#> vect <- as.vector(matrix) -#> invisible(vect) -#> } -#> dists <- get.dists(dist, design, group1, group2) -#> cat(sprintf("Stats for distances between %s and %s", -#> group1, group2), "\n", sprintf("Minimum: %f", min(dists)), -#> "\n", sprintf("Maximum: %f", max(dists)), "\n", sprintf("Median: %f", -#> median(dists)), "\n", sprintf("Mean: %f", mean(dists)), -#> "\n", sprintf("Std. Dev.: %f", sd(dists)), "\n", -#> "\n", sep = "") -#> return(dists) -#> } -#> dist.vect <- c() -#> c <- 1 -#> dist.list <- vector(mode = "list", length = ((length(groups)^2 - -#> length(groups))/2)) -#> list.names <- c() -#> for (i in 1:(length(groups) - 1)) { -#> for (j in (i + 1):length(groups)) { -#> list.names[c] <- paste(groups[i], "vs", groups[j]) -#> dist.list[[c]] <- one.between(dist, design, groups[i], -#> groups[j]) -#> c <- c + 1 -#> } -#> } -#> names(dist.list) <- list.names -#> invisible(dist.list) -#> } -#> <environment: 0x7fad4cf69e48>
mothuR.Rd
close_enough.Rd
longer description (paragraph) goes here
+This is like dplyr::near()
except with much less precision.
NA
- +close_enough(x, y, tol = 10^-3)+ +
x | +a numeric vector |
+
---|---|
y | +another numeric vector |
+
tol | +tolerance (default: |
+
TRUE
if all numbers are near enough within the tolerance, otherwise FALSE
Kelly Sovacool sovacool@umich.edu
+ ++close_enough(0.0004, 0) +#> [1] TRUE +close_enough(0.8887, 0.8884) +#> [1] TRUE +close_enough(1, 2) +#> [1] FALSE + +