Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small fixes to let the package pass R CMD check #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
Package: fisim
Type: Package
Title: Forest Inventory Simulator (fisim) is a package for simulating response
and samplign designs common in forest inventories.
and samplign designs common in forest inventories
Version: 0.1.0
Author: Sebastian Schnell, Henning Aberle
Maintainer: Sebastian Schnell <[email protected]>
URL: http://github.com/sebschnell/
Description: The main purpose of the package is to illustrate basic statisitcal
Description: The main purpose of the package is to illustrate basic statistical
principles of surveys of environmental resources with a focus on forest
inventories. The main intention is to use the package in combination with a
Shiny application to assist teaching in bachelor and master courses on forest
monitoring.
License: What license is it under?
Encoding: UTF-8
LazyData: true
Depends: data.table, sp, maptools, spatstat, rgeos
Depends: R (>= 2.15.1)
Imports:
data.table,
sp,
maptools,
spatstat,
RANN,
rgeos
RoxygenNote: 6.0.1
rgeos,
stats,
utils
RoxygenNote: 7.0.2
10 changes: 2 additions & 8 deletions R/class_definitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,14 @@ is.tree_pop <- function(x) {
#'
#' @param data A \code{\link[data.table]{data.table}} object holding identifiers
#' for the sample and respective point locations and row indices that indicate
#' which population elements are selected into the sample.
#' which population elements are selected into the sample. data must have
#' the columns "id_sample", "id_point", "s" and "ef".
#' @param r_design A \code{character} string indicating the type of the response
#' design. One of the following: "fixed_area", "k_tree", "angle_count".
#' @param r_design_parm A response design specific parameter of type
#' \code{numeric}. For "fixed_area" the plot radius in meter; for "k_tree" the
#' number of trees closest to the sample location; for "angle_count" the basal
#' area factor.
#' @param ef The expansion factor, i.e., the factor that is used to prorate tree
#' attributes to per hectare values (the inverse of the inclusion
#' probabilities). Provided by the particular response design functions.
#' @param ef_alt1 Alternative expansion factor that may be applied when using
#' k-tree sampling.
#' @param ef_alt2 A third alternative expansion factor approximation for k-tree
#' sampling
#'
#' @details The \code{\link[data.table]{data.table}} object (\code{data}) should
#' have the following columns:
Expand Down
22 changes: 22 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,25 @@
#' how often a tree is counted during estimation correcting for edge
#' effects, unitless}}
"hberg_beech"


#' Full census of a stand of random trees
#'
#' A dataset containing tree stem locations and other attributes of 20000 trees
#' randomly generated (by ...) on a 1000m by 500m rectangular plot.
#'
#' @format An object of class \code{\link{tree_pop}}. The data contains 20000
#' rows and 9 columns: \describe{
#' \item{id_tree}{Stem number - one tree can have mulitple stems}
#' \item{id_stem}{Tree number - repetitions possible due to multiple stems}
#' \item{x_tree}{Relative position of the stem center in x-direction}
#' \item{y_tree}{Relative position of the stem center in y-direction}
#' \item{is_dead}{Was the tree alive or dead?}
#' \item{dbh}{Diameter of the stem measured at breast height (1.3m) in cm}
#' \item{ba}{Cross-sectional area of the stem at breast height in square
#' meters}
#' \item{n}{Stem count - helper variable for stem number estimation, unitless}
#' \item{f_edge}{Edge factor - helper variable for edge_correction, indicates
#' how often a tree is counted during estimation correcting for edge
#' effects, unitless}}
"random_tree"
4 changes: 2 additions & 2 deletions R/estimation_design.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Simple random sampling estimator of population means
#'
#' @param data A data.table object with plot-level information of stand
#' @param point_data A data.table object with plot-level information of stand
#' characteristics as coming from the \code{sum_data} function.
#' @param est_col A character vector of column names for which estimates are
#' produced. Used when there is more than one way to expand observations from
Expand All @@ -26,7 +26,7 @@ est_srs <- function(point_data, est_col = NULL) {
dt_est <- point_data$data[,
list(est_appr = names(.SD),
y_hat = sapply(.SD, mean),
v_hat = sapply(.SD, var)/.N),
v_hat = sapply(.SD, stats::var)/.N),
by = list(id_sample, variable),
.SDcols = est_col];
return(dt_est);
Expand Down
6 changes: 6 additions & 0 deletions R/fisim_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
#' @docType package
#' @import data.table spatstat sp rgeos
NULL

# avoid R CMD check warnings due to global variables
utils::globalVariables(c("N", "d", "dbh", "ef", "ef_alt1", "ef_alt2", "f_edge",
"id_point", "id_sample", "id_stem", "id_tree",
"is_edge", "n", "n_corr", "s", "variable", "x_s",
"x_tree", "x_wt", "y_s", "y_tree", "y_wt"))
8 changes: 4 additions & 4 deletions R/sampling_design.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ xy_sample_random <- function(sp_poly, n, M = 1) {
y <- unlist(lapply(tri$tiles, function(x) x$bdry[[1]]$y));

s <- sample(length(a), n*M, prob = w, replace = TRUE);
r1 <- runif(n*M);
r2 <- runif(n*M);
r1 <- stats::runif(n*M);
r2 <- stats::runif(n*M);

n_vtc <- 3; # Number of vertices in a triangle
p4_x <- (1 - r1)*x[(s*n_vtc - 2)] + r1*x[(s*n_vtc - 1)];
Expand Down Expand Up @@ -137,9 +137,9 @@ xy_sample_regular <- function(sp_poly, n, M = 1, cell_size = NULL, random_rot =
r_start <- 0L;
r_end <- 0L;
if (random_rot) {
alpha <- runif(M, min = 0, max = pi);
alpha <- stats::runif(M, min = 0, max = pi);
}
u_d <- cbind(runif(M)*d, runif(M)*d);
u_d <- cbind(stats::runif(M)*d, stats::runif(M)*d);
for (m in seq.int(M)) {
# Enlarge grid to account for possible rotation
x <- seq(1.5*min(e_cent["x", "min"]) + u_d[m, 1], 1.5*max(e_cent["x", "max"]), d);
Expand Down
10 changes: 5 additions & 5 deletions R/utilities.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Helper function to extract population elements into a sample using a list of
#' indices
#'
#' @param dt_pop The population from which to extract sampled elements.
#' @param s An integer matrix where rows represent sample locations and columns
#' @param tree_pop The population from which to extract sampled elements.
#' @param response An integer matrix where rows represent sample locations and columns
#' represent indices of the trees in \code{dt_pop} that are selected at the
#' individual sample locations. Zeroes are used to indicate no neighbours and
#' to ensure a rectangular data format.
Expand Down Expand Up @@ -42,7 +42,7 @@ extract_data <- function(tree_pop, response) {
#'
#' @param tree_sample A \code{\link{tree_sample}} object as coming from
#' the \code{\link{extract_data}} function.
#' @param target_var A character vector of variable names which should be
#' @param target_vars A character vector of variable names which should be
#' summarized at the plot level
#'
#' @return A data.table object with stand characteristics at the plot level.
Expand Down Expand Up @@ -88,7 +88,7 @@ sum_data <- function(tree_sample, target_vars) {
#'
#' @param tree_sample A \code{\link{tree_sample}} object as coming from the
#' \code{\link{extract_data}} function.
#' @param target_var A character vector of variable names which should be
#' @param target_vars A character vector of variable names which should be
#' summarized at the plot level
#'
#' @details For k-tree sampling, individual tree inlcusion probabilities can
Expand Down Expand Up @@ -157,7 +157,7 @@ sum_k_tree <- function(tree_sample, target_vars) {
#'
#' @param tree_sample A \code{\link{tree_sample}} object as coming from
#' the \code{\link{extract_data}} function.
#' @param target_var A character vector of variable names which should be
#' @param target_vars A character vector of variable names which should be
#' summarized at the plot level
#'
#' @return A data.table object with stand characteristics at the plot level.
Expand Down
6 changes: 3 additions & 3 deletions man/est_srs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/extract_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/fisim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions man/hello.Rd

This file was deleted.

28 changes: 28 additions & 0 deletions man/random_tree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions man/rcpp_hello.Rd

This file was deleted.

13 changes: 2 additions & 11 deletions man/response.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sum_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sum_ef.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sum_k_tree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.