Skip to content

Commit

Permalink
Merge pull request #19 from r-spatialecology/CRAN
Browse files Browse the repository at this point in the history
Cran
  • Loading branch information
mhesselbarth authored Jan 10, 2024
2 parents e7fbf93 + e221b81 commit 4e93abe
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 105 deletions.
65 changes: 33 additions & 32 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
Type: Package
Package: onpoint
Title: Helper Functions for Point Pattern Analysis
Version: 1.0.4
Authors@R:
person("Maximilian H.K.", "Hesselbarth",
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1125-9918"))
Maintainer: Maximilian H.K. Hesselbarth <[email protected]>
Description:
Growing collection of helper functions for point pattern analysis. Most functions
are designed to work with the 'spatstat' (<http://spatstat.org>) package. The focus of
most functions are either null models or summary functions for spatial point patterns.
For a detailed description of all null models and summary functions, see
Wiegand and Moloney (2014, ISBN:9781420082548).
URL: https://r-spatialecology.github.io/onpoint/
BugReports: https://github.com/r-spatialecology/onpoint/issues
License: GPL (>= 3)
Depends: R (>= 3.1)
Imports:
ggplot2,
spatstat.explore,
spatstat.geom,
spatstat.random,
stats
Suggests:
covr,
spatstat (>= 2.0.0),
testthat
Encoding: UTF-8
RoxygenNote: 7.2.3
Type: Package
Package: onpoint
Title: Helper Functions for Point Pattern Analysis
Version: 1.0.5
Authors@R:
person("Maximilian H.K.", "Hesselbarth",
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1125-9918"))
Maintainer: Maximilian H.K. Hesselbarth <[email protected]>
Description:
Growing collection of helper functions for point pattern analysis. Most functions
are designed to work with the 'spatstat' (<http://spatstat.org>) package. The focus of
most functions are either null models or summary functions for spatial point patterns.
For a detailed description of all null models and summary functions, see
Wiegand and Moloney (2014, ISBN:9781420082548).
URL: https://r-spatialecology.github.io/onpoint/
BugReports: https://github.com/r-spatialecology/onpoint/issues
License: GPL (>= 3)
Depends: R (>= 3.1)
Imports:
ggplot2,
spatstat.explore,
spatstat.geom,
spatstat.random,
stats
Suggests:
covr,
spatstat (>= 2.0.0),
testthat (>= 3.0.0)
Encoding: UTF-8
RoxygenNote: 7.2.3
Config/testthat/edition: 3
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# onpoint 1.0.5
* Streamlined documentation
* Updated testthat v3
* Updated ggplot2 linewidth internally
* `verbose` does not affect warnings

# onpoint 1.0.4
* Update some plotting functions

Expand Down
14 changes: 6 additions & 8 deletions R/balance_points.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#' balance_points(pattern = input, n = 110)
#' balance_points(pattern = input, n = input_b)
#'
#' @aliases balance_points
#' @rdname balance_points
#'
#' @export
balance_points <- function(pattern, n, verbose = TRUE) {

Expand All @@ -39,15 +36,16 @@ balance_points <- function(pattern, n, verbose = TRUE) {
n <- n$n
}

if (verbose) {
difference_rel <- abs((pattern$n - n)) / pattern$n

difference_rel <- abs((pattern$n - n)) / pattern$n
if (verbose) {

message("> Relative difference between pattern and n: ", round(difference_rel, 2))

if (difference_rel > 0.33) {
warning("Differences between pattern and n more than 0.33.", call. = FALSE)
}
}

if (difference_rel > 0.33) {
warning("Differences between pattern and n more than 0.33.", call. = FALSE)
}

abs((pattern$n - n))
Expand Down
3 changes: 0 additions & 3 deletions R/calc_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#' calc_area(x = dat)
#' }
#'
#' @aliases calc_area
#' @rdname calc_area
#'
#' @keywords internal
calc_area <- function(x){

Expand Down
3 changes: 0 additions & 3 deletions R/center_l_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#' Introduction and methods of edge correction. Journal of Vegetation Science 6, 575–582.
#' <https://doi.org/10.2307/3236356>
#'
#' @aliases center_l_function
#' @rdname center_l_function
#'
#' @export
center_l_function <- function(x, ...) {

Expand Down
3 changes: 0 additions & 3 deletions R/estimate_o_ring.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#' Wiegand, T., Moloney, K.A., 2014. Handbook of spatial point-pattern analysis in
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @aliases estimate_o_ring
#' @rdname estimate_o_ring
#'
#' @export
estimate_o_ring <- function(x, ...) {

Expand Down
3 changes: 0 additions & 3 deletions R/estimate_pcf_fast.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#' Stoyan, D., Stoyan, H., 1994. Fractals, random shapes and point fields.
#' John Wiley & Sons, Chichester, UK. <isbn:978-0-471-93757-9>
#'
#' @aliases estimate_pcf_fast
#' @rdname estimate_pcf_fast
#'
#' @export
estimate_pcf_fast <- function(pattern, ...){

Expand Down
3 changes: 0 additions & 3 deletions R/plot.env_summarized.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
#' x <- summarize_envelope(cluster_env)
#' plot(x)
#'
#' @aliases plot.env_summarized
#' @rdname plot.env_summarized
#'
#' @export
plot.env_summarized <- function(x, col = c("#97CBDE", "#E1B0B5"),
x_lab = NULL, y_lab = NULL, base_size = 10,
Expand Down
11 changes: 4 additions & 7 deletions R/plot_quantums.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
#' interactions among bacteria and between bacteria and the leaf surface.
#' FEMS Microbiology Ecology 91, 1–13. <https://doi.org/10.1093/femsec/fiu034>
#'
#' @aliases plot_quantums
#' @rdname plot_quantums
#'
#' @export
plot_quantums <- function(input,
labels = NULL, color_scale = NULL,
Expand Down Expand Up @@ -142,8 +139,8 @@ plot_quantums <- function(input,
ggplot2::aes(xmin = x.min, xmax = x.max, ymin = quantum_position[1], ymax = quantum_position[2],
fill = type, color = type)) +
ggplot2::geom_ribbon(ggplot2::aes(x = r, ymin = low, ymax = high), fill = "grey") +
ggplot2::geom_line(ggplot2::aes(x = r, y = observed, linetype = "Observed"), size = line_size) +
ggplot2::geom_line(ggplot2::aes(x = r, y = theoretical, linetype = "Theoretical"), size = line_size) +
ggplot2::geom_line(ggplot2::aes(x = r, y = observed, linetype = "Observed"), linewidth = line_size) +
ggplot2::geom_line(ggplot2::aes(x = r, y = theoretical, linetype = "Theoretical"), linewidth = line_size) +
ggplot2::scale_color_manual(name = "", values = color_scale) +
ggplot2::scale_fill_manual(name = "", values = color_scale) +
ggplot2::scale_linetype_manual(name = "", values = c(1, 2)) +
Expand All @@ -155,8 +152,8 @@ plot_quantums <- function(input,
else {
gg_plot <- ggplot2::ggplot(input) +
ggplot2::geom_ribbon(ggplot2::aes(x = r, ymin = low, ymax = high), fill = "grey") +
ggplot2::geom_line(ggplot2::aes(x = r, y = observed, linetype = "Observed"), size = line_size) +
ggplot2::geom_line(ggplot2::aes(x = r, y = theoretical, linetype = "Theoretical"), size = line_size) +
ggplot2::geom_line(ggplot2::aes(x = r, y = observed, linetype = "Observed"), linewidth = line_size) +
ggplot2::geom_line(ggplot2::aes(x = r, y = theoretical, linetype = "Theoretical"), linewidth = line_size) +
ggplot2::scale_linetype_manual(name = "", values = c(1, 2)) +
ggplot2::labs(x = xlab, y = ylab, title = title) +
ggplot2::theme_classic(base_size = base_size) +
Expand Down
3 changes: 0 additions & 3 deletions R/print.env_summarized.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
#' x <- summarize_envelope(cluster_env)
#' print(x)
#'
#' @aliases print.env_summarized
#' @rdname print.env_summarized
#'
#' @export
print.env_summarized <- function(x, return_area = FALSE, digits = 2, ...) {

Expand Down
11 changes: 3 additions & 8 deletions R/rlabel_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' @param nsim Number of patterns to simulate.
#' @param drop If nsim = 1 and drop = TRUE , the result will be a point pattern,
#' rather than a list containing a point pattern.
#' @param verbose If TRUE warning messages are printed.
#'
#' @details
#' Local random labelling function, i.e. marks will be shuffeld only across points
Expand Down Expand Up @@ -38,12 +37,9 @@
#' Wiegand, T., Moloney, K.A., 2014. Handbook of spatial point-pattern analysis in
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @aliases rlabel_local
#' @rdname rlabel_local
#'
#' @export
rlabel_local <- function(X, distance, nsim = 19,
drop = TRUE, verbose = TRUE) {
drop = TRUE) {

# check if pattern is marked
if (!spatstat.geom::is.marked(X) |
Expand Down Expand Up @@ -108,9 +104,8 @@ rlabel_local <- function(X, distance, nsim = 19,
# still return list if nsim > 1 but throw warning
if (nsim != 1) {

if (verbose) {
warning("drop = TRUE only possible for nsim = 1.", call. = FALSE)
}
warning("drop = TRUE only possible for nsim = 1.", call. = FALSE)

}

# return only ppp
Expand Down
3 changes: 0 additions & 3 deletions R/simulate_antecedent_conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
#' Wiegand, T., Moloney, K.A., 2014. Handbook of spatial point-pattern analysis in
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @aliases simulate_antecedent_conditions
#' @rdname simulate_antecedent_conditions
#'
#' @export
simulate_antecedent_conditions <- function(x, i, j, nsim, heterogenous = FALSE, ...) {

Expand Down
3 changes: 0 additions & 3 deletions R/simulate_heterogenous_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#' Wiegand, T., Moloney, K.A., 2014. Handbook of spatial point-pattern analysis in
#' ecology. Chapman and Hall/CRC Press, Boca Raton, USA. <isbn:978-1-4200-8254-8>
#'
#' @aliases simulate_heterogenous_pattern
#' @rdname simulate_heterogenous_pattern
#'
#' @export
simulate_heterogenous_pattern <- function(x, nsim, fix_n = FALSE, ...) {

Expand Down
3 changes: 0 additions & 3 deletions R/split_at.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#' split_at(x = x, pos = 3)
#' }
#'
#' @aliases split_at
#' @rdname split_at
#'
#' @keywords internal
split_at <- function(x, pos) {

Expand Down
3 changes: 0 additions & 3 deletions R/summarize_envelope.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
#'
#' summarize_envelope(cluster_env)
#'
#' @aliases summarize_envelope
#' @rdname summarize_envelope
#'
#' @export
summarize_envelope <- function(x, plot_result = FALSE) {

Expand Down
3 changes: 3 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# onpoint 1.0.5
* Minor cosmetic updates

# onpoint 1.0.4
* Some small function updates

Expand Down
10 changes: 8 additions & 2 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(spatstat.explore)
library(spatstat.geom)
library(onpoint)

test_check("onpoint")
8 changes: 4 additions & 4 deletions tests/testthat/test-balance_points.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
context("test-balance_points")
# context("test-balance_points")

test_that("balance_points works for integer n", {

input <- spatstat.random::rpoispp(lambda = 100)

result <- balance_points(pattern = input, n = 110)
result <- balance_points(pattern = input, n = 110, verbose = FALSE)

expect_equal(object = result$n, expected = 110)
})
Expand All @@ -14,7 +14,7 @@ test_that("balance_points works for ppp n", {
input <- spatstat.random::rpoispp(lambda = 100)
input_b <- spatstat.random::rpoispp(lambda = 100)

result <- balance_points(pattern = input, n = input_b)
result <- balance_points(pattern = input, n = input_b, verbose = FALSE)

expect_equal(object = result$n, expected = input_b$n)
})
Expand All @@ -23,7 +23,7 @@ test_that("balance_points returns error", {

input <- spatstat.random::rpoispp(lambda = 100)

expect_error(object = balance_points(pattern = input, n = 50.5),
expect_error(object = balance_points(pattern = input, n = 50.5, verbose = FALSE),
regexp = "n must be either integer or ppp.")
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-center_l_function.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-center_l_function")
# context("test-center_l_function")

test_that("center_l_function works for point pattern", {

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-estimate_o_ring.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-estimate_o_ring")
# context("test-estimate_o_ring")

test_that("estimate_o_ring returns fv", {

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-estimate_pcf_fast.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
testthat::context("test-estimate_pcf_fast")
# testthat::context("test-estimate_pcf_fast")

testthat::test_that("estimate_pcf returns spatstat.fv object", {

pattern <- spatstat.random::runifpoint(n = 100)

pcf_est <- estimate_pcf_fast(pattern)

testthat::expect_is(pcf_est, "fv")
testthat::expect_s3_class(pcf_est, "fv")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-plot.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-plot")
# context("test-plot")

set.seed(42)
csr_pattern <- spatstat.random::runifpoint(n = 100)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-plot_quantums.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-plot_quantums")
# context("test-plot_quantums")

test_that("plot_quantums returns ggplot", {

Expand All @@ -12,7 +12,7 @@ test_that("plot_quantums returns ggplot", {

plot <- plot_quantums(csr_envelope, ylab = "g(r)")

expect_is(plot, "ggplot")
expect_s3_class(plot, "ggplot")
expect_true(plot$labels$y == "g(r)")
expect_length(plot$layers, n = 4)
})
Expand All @@ -29,7 +29,7 @@ test_that("plot_quantums returns ggplot (only quantum)", {

plot <- plot_quantums(csr_envelope, ylab = "g(r)", full_fun = FALSE)

expect_is(plot, "ggplot")
expect_s3_class(plot, "ggplot")
expect_length(plot$layers, n = 1)
})

Expand All @@ -45,7 +45,7 @@ test_that("plot_quantums returns ggplot only function", {

plot <- plot_quantums(csr_envelope, ylab = "g(r)", quantum = FALSE)

expect_is(plot, "ggplot")
expect_s3_class(plot, "ggplot")
expect_length(plot$layers, n = 3)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-print.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context("test-print")
# context("test-print")

set.seed(42)
csr_pattern <- spatstat.random::runifpoint(n = 100)
Expand Down
Loading

0 comments on commit 4e93abe

Please sign in to comment.