Skip to content

Commit

Permalink
Remove trailing semicolons and whitespace, replace tabs by spaces, for
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Sep 14, 2016
1 parent f95530f commit b80872e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
4 changes: 2 additions & 2 deletions R/ABC_SMC.R
Expand Up @@ -75,11 +75,11 @@ calculate_weight <- function(weights, particles,
#' \dontrun{
#'
#' prior_gen <- function() {
#' return ( rexp(n=2, rate=0.1) );
#' return ( rexp(n=2, rate=0.1) )
#' }
#'
#' prior_dens <- function(val) {
#' return ( dexp( val[1], rate = 0.1) * dexp( val[2], rate = 0.1) );
#' return ( dexp( val[1], rate = 0.1) * dexp( val[2], rate = 0.1) )
#' }
#'
#' require(TESS)
Expand Down
4 changes: 2 additions & 2 deletions R/nLTTDiff.R
Expand Up @@ -152,8 +152,8 @@ nltt_diff <- function(tree1, tree2, distance_method = "abs") {
#' This function takes two ultrametric phylogenetic trees, calculates the normalized Lineage-Through-Time statistic for both trees and then calculates the difference between the two statistics.
#' @title Calculate the difference between two normalized Lineage-Through-Time curves, given two phylogenetic trees.
#' @usage nLTTstat(tree1, tree2, distance_method = "abs")
#' @param tree1 an object of class \code{"phylo"};
#' @param tree2 an object of class \code{"phylo"};
#' @param tree1 an object of class \code{"phylo"}
#' @param tree2 an object of class \code{"phylo"}
#' @param distance_method Chosen measurement of distance between the two nLTT curves, options are (case sensitive):\cr
#' - "abs": use the absolute distance\cr
#' - "squ": use the squared distance;\cr
Expand Down
4 changes: 2 additions & 2 deletions R/plot_nLTT.R
Expand Up @@ -15,7 +15,7 @@
#' This function uses a modified version of the ltt.plot function from \code{"ape"} to plot the normalized number of lineages through normalized time, where the number of lineages is normalized by dividing by the number of tips of the tree, and the time is normalized by the total time between the most common recent ancestor and the present, such that t(MRCA) = 0 & t(present) = 1.
#' @title Normalized version of the ape function ltt.plot
#' @usage nltt_plot(phy, xlab = "Normalized Time", ylab = "Normalized Lineages", ...)
#' @param phy an object of class \code{"phylo"};
#' @param phy an object of class \code{"phylo"}
#' @param xlab a character string (or a variable of mode character)
#' giving the label for the \eqn{x}-axis (default is "Normalized Time").
#' @param ylab a character string (or a variable of mode character)
Expand Down Expand Up @@ -61,7 +61,7 @@ nltt_plot <- function( phy, xlab = "Normalized Time",
#' This is a modified version of the \code{ape} function ltt.lines: add the normalized Lineage-Through-Time statistic of a phylogenetic tree to an already existing plot
#' @title Normalized version of the ape function ltt.lines.
#' @usage nltt_lines(phy, ...)
#' @param phy an object of class \code{"phylo"};
#' @param phy an object of class \code{"phylo"}
#' @param \dots further graphical arguments that can be passed to \code{lines()}
#' @author Thijs Janzen
#' @examples
Expand Down
34 changes: 34 additions & 0 deletions clean_package.sh
Expand Up @@ -3,3 +3,37 @@

# Replace all tabs by two spaces, from http://stackoverflow.com/a/11094620/3364162
find . -name '*.R' ! -type d -exec bash -c 'expand -t 2 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;

cd R

for filename in `ls *.R`
do
echo $filename

# Remove trailing newlines, from http://stackoverflow.com/a/7359879/3364162
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $filename

# Remove trailing semicolons
sed -i 's/;$//' $filename

# Remove trailing whitespace, from http://stackoverflow.com/a/4438318/3364162
sed -i 's/[ \t]*$//' $filename

done

cd ../tests/testthat

for filename in `ls *.R`
do
echo $filename

# Remove trailing newlines, from http://stackoverflow.com/a/7359879/3364162
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $filename

# Remove trailing semicolons
sed -i 's/;$//' $filename

# Remove trailing whitespace, from http://stackoverflow.com/a/4438318/3364162
sed -i 's/[ \t]*$//' $filename

done
6 changes: 3 additions & 3 deletions tests/testthat/test_calculate_weight.R
Expand Up @@ -2,12 +2,12 @@ context("calculate_weight")


test_that("calculate_weight use", {
weights <- rep(1, 2);
particles <- list();
weights <- rep(1, 2)
particles <- list()
for (i in 1:2) {
particles[[i]] <- c(10, 10)
}
sigma <- 1;
sigma <- 1
prior_density_function <- function(x) {
dunif(x[1], min = 0, max = 1000) *
dunif(x[2], min = 0, max = 1000)
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test_mcmc_nltt.R
Expand Up @@ -27,7 +27,7 @@ test_that("mcmc_nltt use", {

expect_equal(
colMeans( mcmc_nltt( tree1, LL_BD, c(1, 0.001), c(TRUE, TRUE),
iterations = 10000, burnin = 1000,
iterations = 10000, burnin = 1000,
thinning = 1, sigma = 1))[[1]],
ML$par[[1]],
tolerance = 0.05
Expand All @@ -48,7 +48,7 @@ test_that("mcmc_nltt abuse", {
set.seed(1) #just to be safe
tree1 <- TESS::tess.sim.taxa(n = 1, nTaxa = 50,
max = 100, lambda = 1.0, mu = 0.0)[[1]]

LL_BD <- function(params, phy) {
lnl <- TESS::tess.likelihood(ape::branching.times(phy),
lambda = params[1], mu = params[2],
Expand All @@ -62,17 +62,17 @@ test_that("mcmc_nltt abuse", {
mcmc_nltt( tree1, LL_BD, c(1, 0.0), c(TRUE, TRUE),
iterations = 10000, burnin = 1000, thinning = 1, sigma = 0.5),
"Cannot propose new value for a parameter with value 0.0."
)
)

expect_error(
expect_error(
mcmc_nltt( 42, LL_BD, c(1, 0.01), c(TRUE, TRUE),
iterations = 10000, burnin = 1000, thinning = 1, sigma = 0.5),
"mcmc_nltt: phy must be of class 'phylo'"
)
)

expect_error(
mcmc_nltt( tree1, LL_BD,c(1, -1), c(TRUE, TRUE),
iterations = 10000, burnin = 1000, thinning = 1, sigma = 0.5),
"mcmc_nltt: initial parameter values have to be above zero"
expect_error(
mcmc_nltt( tree1, LL_BD,c(1, -1), c(TRUE, TRUE),
iterations = 10000, burnin = 1000, thinning = 1, sigma = 0.5),
"mcmc_nltt: initial parameter values have to be above zero"
)
})

1 comment on commit b80872e

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/testthat/test_mcmc_nltt.R:74:29: style: Commas should always have a space after.

​    mcmc_nltt( tree1, LL_BD,c(1, -1), c(TRUE, TRUE),
                            ^

Please sign in to comment.