Skip to content

Commit

Permalink
roxygenization
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Feb 17, 2021
1 parent 36e87b8 commit cb02234
Show file tree
Hide file tree
Showing 57 changed files with 1,784 additions and 1,005 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ lib
library
check
www
examples
^(.+?)\.pdf
^(.+?)\.tar\.gz
^(.+?)\.tgz
Expand Down
32 changes: 28 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ Package: ouch
Type: Package
Title: Ornstein-Uhlenbeck Models for Phylogenetic Comparative Hypotheses
Version: 2.15-1
Date: 2021-02-16
Author: Aaron A. King <kingaa@umich.edu> and Marguerite A. Butler <mbutler@hawaii.edu>
Date: 2021-02-17
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu"),
person(given=c("Marguerite","A."),family="Butler",role=c("ctb")))
Maintainer: Aaron A. King <kingaa@umich.edu>
Description: Fit and compare Ornstein-Uhlenbeck models for evolution along a phylogenetic tree.
Depends: R(>= 3.6), methods, stats, graphics, subplex
Depends: R(>= 3.6)
Imports: methods, stats, graphics, grDevices, utils, subplex
Suggests: ape, geiger
URL: https://kingaa.github.io/ouch/
License: GPL-3
LazyLoad: true
Collate: ouchtree.R ape2ouch.R glssoln.R rmvnorm.R brown.R hansen.R methods.R paint.R plot.R
LazyData: true
RoxygenNote: 7.1.1
BugReports: https://github.com/kingaa/ouch/issues/
Encoding: UTF-8
Collate:
'anolis.R'
'package.R'
'ouchtree.R'
'ape2ouch.R'
'bimac.R'
'rmvnorm.R'
'glssoln.R'
'brown.R'
'simulate.R'
'hansen.R'
'bootstrap.R'
'coef.R'
'loglik.R'
'paint.R'
'plot.R'
'print.R'
'summary.R'
'update.R'
52 changes: 29 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ REXE = R --vanilla
RCMD = $(REXE) CMD
RCMD_ALT = R --no-save --no-restore CMD
RSCRIPT = Rscript --vanilla
REPODIR = ../www

PDFLATEX = pdflatex
BIBTEX = bibtex
Expand All @@ -18,31 +19,27 @@ PKGVERS = $(PKG)_$(VERSION)
SOURCE=$(shell ls R/*R src/*.c src/*.h data/*)
CSOURCE=$(shell ls src/*.c)
TESTS=$(shell ls tests/*R)
REVDEPS=surface mvSLOUCH pmc

default:
@echo $(PKGVERS)

.PHONY: clean win wind tests check

dist manual vignettes: export R_QPDF=qpdf
dist manual vignettes: export R_GSCMD=gs
dist manual vignettes: export GS_QUALITY=ebook
dist manual vignettes: export R_HOME=$(shell $(REXE) RHOME)
roxy dist manual vignettes: export R_HOME=$(shell $(REXE) RHOME)
check xcheck xxcheck: export FULL_TESTS=yes
xcheck tests: export R_PROFILE_USER=$(CURDIR)/.Rprofile
session htmldocs vignettes data tests manual: export R_LIBS=$(CURDIR)/library
session: export R_DEFAULT_PACKAGES=datasets,utils,grDevices,graphics,stats,methods,ouch
xxcheck: export R_LIBS=$(CURDIR)/check

includes:

headers:

inst/include/%.h: src/%.h
$(CP) $^ $@
dist revdeps session tests check xcheck xxcheck: export R_KEEP_PKG_SOURCE=yes
revdeps xcheck tests: export R_PROFILE_USER=$(CURDIR)/.Rprofile
revdeps session xxcheck htmldocs vignettes data tests manual: export R_LIBS=$(CURDIR)/library
session: export R_DEFAULT_PACKAGES=datasets,utils,grDevices,graphics,stats,methods,tidyverse,subplex,ouch

htmldocs: inst/doc/*.html

htmlhelp: install
rsync -avz library/ouch/html/ www/manual
(cd www/manual; (cat links.ed && echo w ) | ed - 00Index.html)

vignettes: manual install
$(MAKE) -C www/vignettes

Expand All @@ -59,13 +56,17 @@ www/NEWS.html: inst/NEWS.Rd
session: install
exec $(REXE)

revdeps: install
mkdir -p library check
$(REXE) -e "pkgs <- strsplit('$(REVDEPS)',' ')[[1]]; download.packages(pkgs,destdir='library',repos='https://mirrors.nics.utk.edu/cran/')"
$(RCMD) check --library=library -o check library/*.tar.gz

roxy: $(SOURCE)
## $(REXE) -e "pkgload::load_all(compile=FALSE); devtools::document(roclets=c('rd','collate','namespace'))"
$(REXE) -e "pkgbuild::compile_dll(); devtools::document(roclets=c('rd','collate','namespace'))"

dist: NEWS $(PKGVERS).tar.gz

$(PKGVERS).tar.gz: $(SOURCE) $(TESTS) includes headers
$(PKGVERS).tar.gz: $(SOURCE) $(TESTS)
$(RCMD) build --force --no-manual --resave-data --compact-vignettes=both --md5 .

binary: dist
Expand All @@ -74,9 +75,9 @@ binary: dist
rm -rf plib

publish: dist manual news
$(RSCRIPT) -e 'drat::insertPackage("$(PKGVERS).tar.gz",repodir="../www",action="prune")'
-$(RSCRIPT) -e 'drat::insertPackage("$(PKGVERS).tgz",repodir="../www",action="prune")'
-$(RSCRIPT) -e 'drat::insertPackage("$(PKGVERS).zip",repodir="../www",action="prune")'
$(RSCRIPT) -e 'drat::insertPackage("$(PKGVERS).tar.gz",repodir="$(REPODIR)",action="prune")'
-$(RSCRIPT) -e 'drat::insertPackage("$(PKGVERS).tgz",repodir="$(REPODIR)",action="prune")'
-$(RSCRIPT) -e 'drat::insertPackage("$(PKGVERS).zip",repodir="$(REPODIR)",action="prune")'
$(CP) $(PKG).pdf ../www/manuals

win: dist
Expand All @@ -98,10 +99,10 @@ qqcheck: dist
$(RCMD) check --library=check -o check --no-codoc --no-examples --no-vignettes --no-manual --no-tests $(PKGVERS).tar.gz

xcheck: dist
mkdir -p check
mkdir -p check library
$(RCMD_ALT) check --no-stop-on-test-error --as-cran --library=library -o check $(PKGVERS).tar.gz

xxcheck: xcheck
xxcheck: install xcheck
mkdir -p check
$(REXE) -d "valgrind --tool=memcheck --track-origins=yes --leak-check=full" < check/$(PKG).Rcheck/$(PKG)-Ex.R 2>&1 | tee $(PKG)-Ex.Rout

Expand All @@ -123,10 +124,15 @@ install: library/$(PKG)

library/$(PKG): dist
mkdir -p library
$(RCMD) INSTALL --library=library $(PKGVERS).tar.gz
$(RCMD) INSTALL --html --library=library $(PKGVERS).tar.gz

remove:
-$(RCMD) REMOVE --library=library $(PKG)
if [ -d library ]; then \
$(RCMD) REMOVE --library=library $(PKG); \
rmdir library; \
fi

fresh: clean remove

inst/doc/*.html: install

Expand Down
49 changes: 30 additions & 19 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
useDynLib(ouch,.registration=TRUE)
# Generated by roxygen2: do not edit by hand

export(ape2ouch)
export(brown)
export(hansen)
export(ouchtree)
export(paint)
exportMethods(bootstrap)
exportMethods(coef)
exportMethods(logLik)
exportMethods(plot)
exportMethods(print)
exportMethods(show)
exportMethods(simulate)
exportMethods(summary)
exportMethods(update)
import(methods)
importFrom(subplex,subplex)
importFrom(stats,deviance,simulate,update,coef,logLik,optim,
rnorm,runif,setNames)
importFrom(utils,head,tail)
importFrom(graphics,plot,par,text)
importFrom(grDevices,rainbow)
exportClasses('ouchtree','browntree','hansentree')
exportMethods(
'plot','logLik','summary','coef','coerce',
'print','show',
'simulate','update','bootstrap'
)
export(
ouchtree,
brown,
hansen,
ape2ouch,
paint
)
importFrom(graphics,par)
importFrom(graphics,text)
importFrom(stats,coef)
importFrom(stats,logLik)
importFrom(stats,optim)
importFrom(stats,rnorm)
importFrom(stats,runif)
importFrom(stats,setNames)
importFrom(stats,simulate)
importFrom(stats,update)
importFrom(subplex,subplex)
importFrom(utils,head)
importFrom(utils,tail)
useDynLib(ouch, .registration = TRUE)
43 changes: 43 additions & 0 deletions R/anolis.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' Greater Antillean anolis lizard sexual size dimorphism data
#'
#' The dataset consists of sexual size-dimorphism data for 38 species of anoles from Cuba, Hispaniola, Jamaica, and Puerto Rico (Butler, Schoener, and Losos 2000).
#' Each of these species belongs to one of six microhabitat types, or \dQuote{ecomorphs} (sensu Williams, 1972):
#' trunk-ground, grass-bush, trunk, trunk-crown, twig, and crown-giant.
#' The data were used to demonstrate an evolutionary association between habitat type and degree of sexual size dimorphism.
#'
#' Size dimorphism was calcuated as the log-ratio of male snout-to-vent length to female snout-to-vent length (males are larger).
#'
#' In this example, we tested three models of evolution:
#' Brownian motion, Ornstein-Uhlenbeck with one global optimum, and Ornstein-Uhlenbeck with 7 optima (one for each ecomorph type plus an additional one for an \dQuote{unknown} type).
#'
#' For the 7-optima model, we assigned each terminal branch to an optimum according to the ecomorph type of the extant species.
#' Because we had no information to help guide hypotheses about internal branches, we assigned
#' internal branches to the \dQuote{unknown} selective regime.
#' The phylogeny of these species is consistent with and adaptive radiation, with a burst of speciation events early in the evolutionary history of this clade (see phylogeny in Butler & King (2004) or example below).
#'
#' @name anolis.ssd
#' @rdname anolis_ssd
#' @docType data
#' @format
#' A data frame with 38 observations on the following 6 variables.
#' \describe{
#' \item{node}{Labels for the nodes.}
#' \item{species}{Names of extant species.}
#' \item{log.SSD}{Log sexual size dimorphism of extant species.}
#' \item{ancestor}{Ancestor node.}
#' \item{time}{Time of node.}
#' \item{OU.1}{a factor with levels \code{ns}}
#' \item{OU.7}{a factor with levels corresponding to ecomorph
#' (\code{tg} \code{tc} \code{gb} \code{cg} \code{tw} \code{tr} \code{anc})}
#' }
#' @author Marguerite A. Butler, Aaron A. King
#' @references
#' \Butler2000
#'
#' \Williams1972
#'
#' @source \Butler2004
#' @keywords models
#' @example examples/anolis.R
#'
NULL
54 changes: 34 additions & 20 deletions R/ape2ouch.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
# This function takes a tree file in the phylo format (from
# ape/read.tree) and creates an ouchtree object.
# The option exists whereby users can change branch lengths
# while keeping the same topology.
#
# t = object of type 'phylo', as returned by ape/read.tree
# branch.lengths = optional branch length vector in same
# order as t$edge.length; default is to use t$edge.length
#
# D. Ackerly, dackerly at berkeley dot edu, July 18, 2006.
# Modified by A.A. King, kingaa at umich dot edu, 5/15/2007.

#' Convert an "ape" tree to an "ouch" tree.
#'
#' \code{ape2ouch} translates \pkg{ape}'s \code{phylo} representation of a phylogenetic tree into \pkg{ouch}'s \code{ouchtree} representation.
#' The user can change the branch lengths while preserving the topology.
#'
#' @param tree a tree of class \code{phylo} created in package \pkg{ape}.
#' @param scale if \code{scale=TRUE}, the tree's depth will be scaled to 1.
#' If \code{scale} is a number, then the branch lengths will be scaled by this number.
#' @param branch.lengths optional vector of branch lengths.
#' @author A. A. King, D. Ackerly
#' @keywords models
#'
#' @rdname ape2ouch
#' @include ouchtree.R
#' @export ape2ouch
ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
## This function takes a tree file in the phylo format (from
## ape/read.tree) and creates an ouchtree object.
## The option exists whereby users can change branch lengths
## while keeping the same topology.
##
## t = object of type 'phylo', as returned by ape/read.tree
## branch.lengths = optional branch length vector in same
## order as t$edge.length; default is to use t$edge.length
##
## D. Ackerly, July 18, 2006.
## Modified by A.A. King, 5/15/2007.

if (!inherits(tree,'phylo'))
stop(sQuote("tree")," must be of class ",sQuote("phylo"))

nnodes <- nrow(tree$edge)+1 # number of nodes
n.term <- length(tree$tip.label) # number of terminal nodes
n.int <- nnodes-n.term # internal nodes
n.int <- nnodes-n.term # internal nodes

tmp <- matrix(NA,nnodes,2)
tmp[-1,1:2] <- tree$edge
Expand All @@ -33,9 +47,9 @@ ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
for (n in 2:nnodes) {
anc <- which(tmp[,2]==tmp[n,1])
if (length(anc)>1) stop("invalid tree")
if (length(anc)>0) { # the node has a non-root ancestor
if (length(anc)>0) { # the node has a non-root ancestor
ancestor[n] <- node[anc]
} else { # the node has the root as an ancestor
} else { # the node has the root as an ancestor
ancestor[n] <- node[1]
}
}
Expand All @@ -57,11 +71,11 @@ ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
}

ouchtree(
nodes=node,
ancestors=ancestor,
times=times,
labels=species
)
nodes=node,
ancestors=ancestor,
times=times,
labels=species
)
}

branch.height <- function (node, anc, bl, k) {
Expand Down
57 changes: 57 additions & 0 deletions R/bimac.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#' Anolis bimaculatus lizard size data.
#'
#' This is the \emph{Anolis bimaculatus} dataset used in Butler & King (2004).
#' It is used to test a hypothesis of character displacement using an interspecific dataset of body sizes and current data on sympatry/allopatry.
#' The data frame has the following columns:
#' \code{species} which are species names,
#' \code{size} which is the phenotypic data,
#' and the variables \code{ancestor} and \code{time} which specify the topology of the phylogeny and the location of the nodes in time, respectively.
#' The columns \code{OU.1}, \code{OU.3}, \code{OU.4}, and \code{OU.LP} specify four hypothetical arrangements of selective regimes.
#' Explanations of the data follow:
#' \describe{
#' \item{Body size.}{
#' We use the phenotypic data and phylogeny of Losos (1990), which employed the head lengths (of males) as a proxy for body size.
#' In this group of lizards, head length correlates very strongly with snout-to-vent length and the cube root of mass, which are standard measures of body size.
#' The data are head lengths in mm; note that we use the log of this value in analyses.
#' }
#' \item{Tree topology}{
#' The tree topology is encoded via two vectors: \code{ancestor} and \code{time}.
#' Each node of the' phylogenetic tree has a corresponding row in the data frame, numbered from 1 to 45.
#' The columns \code{ancestor} and \code{time} specify the phylogeny.
#' The \code{ancestor} variable specifies the topology: it is a list indicating the ancestor of each node.
#' The root node has ancestor 0.
#' The variable \code{time} specifies the temporal location of each node, with the root node being at time 0.
#' }
#' \item{Specifications of selective regimes.}{
#' (Columns \code{OU.1}, \code{OU.3}, \code{OU.4}, \code{OU.LP}).
#' These columns are factors, the levels of which correspond to the \dQuote{paintings} of the respective adaptive regime hypotheses onto the phylogeny.
#' Each selective regime is named (small, medium, large, etc.).
#' Each column corresponds to a different painting of the selective regimes, and thus to a different hypothesis.
#' In this example, there are 3 alternative models (see Butler & King 2004): \code{OU.4} is 4-regime model, \code{OU.3} is 3-regime model (all ancestors are medium), \code{OU.LP} is the linear parsimony model.
#' }
#' }
#'
#' @name bimac
#' @docType data
#' @format A data frame with 45 observations on the following 8 variables.
#' \describe{
#' \item{node}{Labels for the nodes.}
#' \item{species}{Species names for extant species.}
#' \item{size}{Body size (head length in mm) of extant species.}
#' \item{ancestor}{Ancestral node.}
#' \item{time}{Time of node.}
#' \item{OU.1}{a factor with levels \code{ns}}
#' \item{OU.3}{a factor with levels \code{small}, \code{medium}, \code{large}}
#' \item{OU.4}{a factor with levels \code{small}, \code{medium}, \code{large}, \code{anc}}
#' \item{OU.LP}{a factor with levels \code{small}, \code{medium}, \code{large}}
#' }
#' @author Marguerite A. Butler and Aaron A. King
#' @references
#' \Lazell1972
#'
#' \Losos1990
#' @source \Butler2004
#' @keywords models
#' @example examples/bimac.R
#'
NULL
Loading

0 comments on commit cb02234

Please sign in to comment.