Skip to content

Commit

Permalink
Merge pull request #9 from AlbanSagouis/dev
Browse files Browse the repository at this point in the history
Preparation for CRAN submission
  • Loading branch information
AlbanSagouis authored Dec 7, 2023
2 parents 3948453 + 8e695c1 commit 4ae826d
Show file tree
Hide file tree
Showing 27 changed files with 329 additions and 264 deletions.
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
^.*\.Rproj$
^\.Rproj\.user$
cran-comments.md
CONTRIBUTING.md
codemeta.json
^revdep$
^README\.Rmd$
^README-.*\.png$
^NEWS\.md$
^LICENSE\.md$
^examples$
^\.travis\.yml$
^\.github$
^doc$
^Meta$
^codemeta\.json$
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
#
# NOTE: This workflow is overkill for most R packages and
# check-standard.yaml is likely a better choice.
# usethis::use_github_action("check-standard") will install it.
on:
push:
branches: [main, master]
Expand All @@ -18,18 +22,27 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/pkgcheck.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ mobsim.Rproj
revdep/
.Rproj.user
mobsim_package.Rproj

.DS_Store
/doc/
/Meta/
24 changes: 15 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
Package: mobsim
Type: Package
Title: Spatial Simulation and Scale-Dependent Analysis of Biodiversity Changes
Version: 0.2.0.9015
Authors@R: c(person("Felix", "May", email = "[email protected]", role = c("aut","cre")),
person("Alban", "Sagouis", email = "[email protected]", role = c("aut"))
)
Date: 2022-03-04
Version: 0.3.0
Authors@R: c(
person("Felix", "May", email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-1106-8188")),
person("Alban", "Sagouis", email = "[email protected]",
role = "aut",
comment = c(ORCID = "0000-0002-3827-1063"))
)
Date: 2023-12-12
Description: Tools for the simulation, analysis and sampling of spatial
biodiversity data (May et al. 2017) <doi:10.1101/209502>.
In the simulation tools user define the numbers of
Expand All @@ -14,15 +19,15 @@ Description: Tools for the simulation, analysis and sampling of spatial
and accumulation curves, species-area relationships and the distance
decay of similarity.
License: GPL (>= 3)
LazyData: TRUE
Imports:
Rcpp,
vegan,
sads (>= 0.4.1),
grDevices,
utils,
graphics,
stats
stats,
methods
LinkingTo:
Rcpp
Suggests:
Expand All @@ -31,9 +36,10 @@ Suggests:
testthat (>= 3.0.0), mockery,
knitr
Config/testthat/edition: 3
Config/testthat/parallel: true
VignetteBuilder: knitr
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Language: en-GB
Encoding: UTF-8
Source: https://prograide.com/pregunta/73922/avertissement-concernant-lutf-8-avec-roxygen2
URL: https://github.com/AlbanSagouis/mobsim
BugReports: https://github.com/AlbanSagouis/mobsim
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ export(sim_thomas_coords)
export(spec_sample)
export(spec_sample_curve)
importFrom(Rcpp,sourceCpp)
importFrom(methods,is)
importFrom(sads,rsad)
useDynLib(mobsim)
useDynLib(mobsim, .registration = TRUE)
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mobsim 0.2.1
mobsim 0.3.0
================================================================================

### POTENTIAL CODE BREAK
Expand Down
23 changes: 12 additions & 11 deletions R/Diversity_Area_Relationships.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ div_rect <- function(x0, y0, xsize, ysize, comm)
abund <- abund[abund > 0]
relabund <- abund/sum(abund)

shannon <- - sum(relabund * log(relabund))
shannon <- -sum(relabund * log(relabund))

n <- sum(abund)
if (n > 1)
#simpson <- (n/(n-1)) * (1 - sum(relabund^2))
simpson <- 1- sum(relabund^2)
simpson <- 1 - sum(relabund^2)
else
simpson <- NA

Expand Down Expand Up @@ -123,12 +123,11 @@ div_rand_rect <- function(prop_area = 0.25, comm, n_rect = 100,
area <- dx_plot * dy_plot * prop_area
square_size <- sqrt(area)

if (square_size <= min(c(dx_plot, dy_plot))){
if (square_size <= min(c(dx_plot, dy_plot))) {
dx_rect <- square_size
dy_rect <- square_size
} else
{
if (dx_plot >= dy_plot){
} else {
if (dx_plot >= dy_plot) {
dx_rect <- dx_plot*prop_area
dy_rect <- dy_plot
} else {
Expand All @@ -143,7 +142,7 @@ div_rand_rect <- function(prop_area = 0.25, comm, n_rect = 100,
max = comm$y_min_max[2] - dy_rect)

div_plots <- mapply(div_rect, xpos, ypos,
MoreArgs=list(xsize = dx_rect, ysize = dy_rect,
MoreArgs = list(xsize = dx_rect, ysize = dy_rect,
comm = comm))
if (exclude_zeros == T)
div_plots <- div_plots[, div_plots["n_species",] > 0]
Expand Down Expand Up @@ -204,7 +203,7 @@ divar <- function(comm, prop_area = seq(0.1, 1, by = 0.1), n_samples = 100,
warning("Subplot areas larger than the community size are ignored!")
prop_area <- prop_area[prop_area <= 1]

if (class(comm) != "community")
if (!is(comm, "community"))
stop("DiVAR requires a community object as input. See ?community.")

n_scales <- length(prop_area)
Expand Down Expand Up @@ -292,7 +291,7 @@ abund_rect <- function(x0, y0, xsize, ysize, comm)
y <- comm$census$y

# logical vector which trees are in the sampling rectangle
in_rect <- (x >= x0 & x < (x0+xsize) & y >= y0 & y < (y0+ysize))
in_rect <- (x >= x0 & x < (x0 + xsize) & y >= y0 & y < (y0 + ysize))

abund <- table(comm$census$species[in_rect])
return(abund)
Expand All @@ -318,6 +317,7 @@ abund_rect <- function(x0, y0, xsize, ysize, comm)
#' dd1 <- dist_decay(sim_com1, prop_area = 0.005, n_samples = 20)
#' plot(dd1)
#'
#' @importFrom methods is
#'@export
#'
dist_decay <- function(comm, prop_area = 0.005, n_samples = 20,
Expand All @@ -329,14 +329,15 @@ dist_decay <- function(comm, prop_area = 0.005, n_samples = 20,
if (length(prop_area) != 1L)
stop("prop_area has to be of length 1")

if (class(comm) != "community")
if (!is(comm, "community"))
stop("dist_decay requires a community object as input. See ?community.")

dx_plot <- comm$x_min_max[2] - comm$x_min_max[1]
dy_plot <- comm$y_min_max[2] - comm$y_min_max[1]
area <- dx_plot * dy_plot * prop_area

samples1 <- sample_quadrats(comm, n_quadrats = n_samples, quadrat_area = area,
samples1 <- sample_quadrats(comm, n_quadrats = n_samples,
quadrat_area = area,
avoid_overlap = T, plot = F)
com_mat <- samples1$spec_dat[rowSums(samples1$spec_dat) > 0,]
d <- stats::dist(samples1$xy_dat[rowSums(samples1$spec_dat) > 0,])
Expand Down
6 changes: 3 additions & 3 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ sSAC1_C <- function(x, y, id_spec) {
}

#' Thomas process individual distribution simulation for one species
#'
#'
#' Usually used internally inside \code{\link{sim_thomas_coords}}
#' This function randomly draws points (individuals) around one or several mother points using Rcpp.
#' The function is an efficient re-implementation of the rThomas function from the spatstat package.
#'
#'
#' @name rThomas_rcpp
#'
#'
#' @param n_points The total number of points (individuals).
#' @param n_mother_points Number of mother points (= cluster centres).
#' @param xmother Vector of \code{n_mother_points} x coordinates for the mother points.
Expand Down
16 changes: 8 additions & 8 deletions R/SAC_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,23 @@ rare_curve <- function(abund_vec)
#' plot(sac1)
#'
#' @export
#' @importFrom methods is
#'
spec_sample_curve <- function(comm, method = c("accumulation" ,"rarefaction"))
{
if (class(comm) != "community")
if (!is(comm, "community"))
stop("spec_sample_curve requires a community object as input. See ?community.")

out_dat <- data.frame(n = 1:nrow(comm$census))

method <- match.arg(method, several.ok = TRUE)

if ("accumulation" %in% method){
if ("accumulation" %in% method) {
out_dat$spec_accum <- sSAC1_C(comm$census$x, comm$census$y,
as.integer(comm$census$species))
}

if ("rarefaction" %in% method){
if ("rarefaction" %in% method) {
abund <- community_to_sad(comm)
out_dat$spec_rarefied <- rare_curve(abund)

Expand Down Expand Up @@ -156,19 +157,19 @@ plot.spec_sample_curve <- function(x, ...)
ylab = "Expected no.of species",
main = "Species sampling curves", ...)

if (ncol(x) == 2){
if (names(x)[2] == "spec_accum"){
if (ncol(x) == 2) {
if (names(x)[2] == "spec_accum") {
legend_text <- c("Accumulation")
line_col <- "red"
}
if (names(x)[2] == "spec_rarefied"){
if (names(x)[2] == "spec_rarefied") {
legend_text <- c("Rarefaction")
line_col <- "blue"
}
graphics::lines(x[[1]], x[[2]], col = line_col)
}

if (ncol(x) == 3){
if (ncol(x) == 3) {
legend_text <- c("Accumulation","Rarefaction")
line_col <- c("red","blue")
graphics::lines(x[[1]], x[[2]], col = line_col[1])
Expand All @@ -177,4 +178,3 @@ plot.spec_sample_curve <- function(x, ...)

graphics::legend("bottomright", legend = legend_text, lty = 1, col = line_col)
}

4 changes: 2 additions & 2 deletions R/Sample_quadrats.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' specnumber(comm_mat1$spec_dat)
#' diversity(comm_mat1$spec_dat, index = "shannon")
#'
#'
#' @importFrom methods is
#' @export
#'
sample_quadrats <- function(comm, n_quadrats = 20, quadrat_area = 0.01,
Expand All @@ -42,7 +42,7 @@ sample_quadrats <- function(comm, n_quadrats = 20, quadrat_area = 0.01,
x0 = 0, y0 = 0, delta_x = 0.1, delta_y = 0.1,
seed = NULL)
{
if (class(comm) != "community")
if (!is(comm, "community"))
stop("comm has to be a community object")
if (round(n_quadrats, 0) != n_quadrats) stop("n_quadrats has to be an integer")

Expand Down
Loading

0 comments on commit 4ae826d

Please sign in to comment.