Distance logo

Distance Developers Guide

How to build R components

Jump down to:

Find out tool versions

R:

R --version
R version 3.1.0 (2014-04-10) -- "Spring Dance"

Build R DSM and MRDS analysis engines

chdir %BASE%\Analysis Engines\DSM\Engine\
chdir %BASE%\Analysis Engines\MRDS\Engine\mrds\

R CMD --no-manual check dsm
R CMD --no-manual check mrds

R CMD check --as-cran dsm
R CMD check --as-cran mrds

R CMD INSTALL --build dsm
R CMD INSTALL --build mrds

mkdir local
R CMD INSTALL -l local --build dsm
R CMD INSTALL -l local --build mrds

dsm_M.N.R.zip
mrds_M.N.R.zip

Build R DSM and MRDS analysis engines from within R

library(devtools)

check("dsm", args="--no-manual")
check("mrds", args="--no-manual")

install("mrds")
install("dsm")

build("dsm",binary=T)
build("mrds",binary=T)

dsm_M.N.R.zip
mrds_M.N.R.zip

Create R DSM and MRDS Roxygen documentation

library(devtools)

load_all("dsm")
load_all("mrds")

document("dsm")
document("mrds")

Run DSM and MRDS examples

library(devtools)

load_all("dsm")
load_all("mrds")

run_examples("dsm")
run_examples("mrds")

Install source package and build zip via package

Alternatively, one can build a .tar.gz package:

R CMD build dsm
R CMD build mrds

R CMD INSTALL --build dsm_M.N.R.tar.gz
R CMD INSTALL --build mrds_M.N.R.tar.gz

Copy R packages for use in Visual Basic and release

copy %BASE%\Analysis Engines\DSM\Engine\dsm_M.N.R.zip %BASE%\Analysis Engines\Shared Stuff\NEngineInterfaceUtilities\RPackages\
copy %BASE%\Analysis Engines\MRDS\Engine\mrds\mrds_M.N.R.zip %BASE%\Analysis Engines\Shared Stuff\NEngineInterfaceUtilities\RPackages\

How to write tests

Distance’s R tests are written in testthat. For more information see:


How to run tests from within R

library(testthat)

library(dsm)

test_file("tests/testthat/test_input.R")

test_file("tests/testthat/")

test_package("dsm")

test_file("tests/testthat/test_input.R", "minimal")

How to run tests from outwith R

library(testthat)
library(PACKAGENAME)
test_check("PACKAGENAME")

chdir dsm\tests\

R -file testthat.R

Run MRDS and DSM within R using captured input files

Within R GUI:

Within R batch mode:

Rcmd.exe BATCH in.r log.r

Capture MCDS and DSM input files from within Distance for Windows

If reusing files elsewhere check to ensure that any paths within the files are updated.


Reproduce CDS and MCDS plots of detection function and pdf using R

#this reads in the file just created
forplot<-read.table(file="plot.txt", header=T, sep="\t", dec=".")
#note, depending on your language, dec might be "," rather than "."
#this plots the detection function or pdf (if point transects)
plot(forplot$C1, forplot$C2, type="l", ylim=c(0,max(forplot$C4)),
xlab="Distance", ylab="Detection probability")
#Define labels as you wish
#this adds in the data bars
lines(c(0,0), c(forplot$C3[1], forplot$C4[1]))
lines(forplot$C3, forplot$C4)

Reproduce CDS and MCDS qq-plots using R

#this reads in the file just created
forplot<-read.table(file="plot.txt", header=T, sep="\t", dec=".")
#note, depending on your language, dec might be "," rather than "."
#this plots the detection function or pdf (if point transects)
plot(forplot$C1, forplot$C2, type="p", ylim=c(0,max(forplot$C4)),
pch = ".", xlab="Empirical distribution function",
ylab="Fitted cumulative distribution function")
#Define labels as you wish
#this adds in the (0,0) (1,1) line
lines(c(0,1), c(0,1))

Reproduce MCDS plots of detection functions produced with non-factor covariates within using R

#this reads in the file just created
forplot<-read.table(file="plot.txt", header=T, sep="\t", dec=".")
#note, depending on your language, dec might be "," rather than "."
#this plots the detection function or pdf (if point transects)
plot(forplot$C1, forplot$C2, type="l", ylim=c(0,1),
xlab="Distance", ylab="Detection probability")
#Define labels as you wish
#this adds in other two lines
lines(forplot$C3, forplot$C4, lty=2)
lines(forplot$C5, forplot$C6, lty=3)