Skip to content

Commit

Permalink
Added dplyr in suggests
Browse files Browse the repository at this point in the history
Re-used dplyr functions and pipe in vignette
  • Loading branch information
ArthurBailly committed Nov 7, 2024
1 parent 2d0e198 commit f24f51f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ Suggests:
curl,
geodata,
httr2,
pkgdown
pkgdown,
dplyr
RoxygenNote: 7.3.2
4 changes: 2 additions & 2 deletions R/divide_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @return If tree_coord isn't supplied, returns a data-frame containing as many rows as there are corners corresponding to the subplots, and the following columns :
#' - `plot_ID_corner`: If dealing with multiple plots : the plot code
#' - `subplot_id`: The automatically generated subplot code, using the following rule : subplot_X_Y
#' - `x` and `y` (or the column names provided by rel_coord) : the relative X-axis and Y-axis coordinates of subplots corners.
#' - `x_rel` and `y_rel` (or the column names provided by rel_coord) : the relative X-axis and Y-axis coordinates of subplots corners.
#' - `x_proj` and `y_proj` (or the column names provided by proj_coord) : if proj_coord is supplied, the projected X-axis and Y-axis coordinates of subplots corners
#'
#' If tree_coord is supplied, returns a list containing the previous data-frame and a data-frame containing for each tree :
Expand Down Expand Up @@ -53,7 +53,7 @@ divide_plot <- function(rel_coord, proj_coord = NULL, grid_size, plot_ID_corner

# Parameters verification ----------------------------------------------------
if (is.matrix(rel_coord)) {
rel_coord <- data.frame(x=rel_coord[,1],y=rel_coord[,2])
rel_coord <- data.frame(x_rel=rel_coord[,1],y_rel=rel_coord[,2])
}
if (!is.null(proj_coord) && !is.data.frame(proj_coord)) {
proj_coord <- data.frame(x_proj=proj_coord[,1], y_proj=proj_coord[,2])
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-dividePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("divide_plot on relative coordinates only", {
# Test when rel_coord is a matrix (colnames aren't supplied)
rel_coord <- matrix(c(0,100,0,100,0,0,100,100), ncol=2)
subplots <- divide_plot(rel_coord = rel_coord, grid_size = 50)
expect_equal(subplots[1:4,] , data.frame(subplot_id=rep("subplot_0_0",4),x=c(0,50,0,50), y=c(0,0,50,50)))
expect_equal(subplots[1:4,] , data.frame(subplot_id=rep("subplot_0_0",4),x_rel=c(0,50,0,50), y_rel=c(0,0,50,50)))

# Test when rel_coord is a data.table
rel_coord <- data.table(expand.grid(x_field = c(0, 100), y_field = c(0, 100)))
Expand Down Expand Up @@ -182,4 +182,4 @@ test_that("divide_plot with tree coordinates", {
expect_equal(names(multiple_subplots$tree_coord) , c("X","Y","plot_id","subplot_id","H","AGB"))


})
})
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ subplots <- divide_plot(
For the purposes of summarizing and representing subplots (coming in the next section), the function returns the coordinates of subplot corners (keeping column names) but can also assign to each tree its subplot with the `tree_coord` :

```{r divide_plot_trees}
trees <- trees[,c("xRel","yRel","plot","D","WD","H")]
trees <- trees %>% dplyr::relocate(xRel, yRel, .before = everything()) # to get the coordinates at the first two columns
subplots <- divide_plot(
rel_coord = check_plot_trust_field$cornerCoord[c("Xrel","Yrel")],
Expand All @@ -204,9 +204,7 @@ The function can handle as many plots as you wish, using the `plot_ID_corner` an
```{r divide_multiple_plots}
multiple_plots <- rbind(check_plot_trust_GPS$cornerCoord[c("Xrel","Yrel")], check_plot_trust_GPS$cornerCoord[c("Xrel","Yrel")])
multiple_plots$plot_ID = rep(c("NB1","NB2"),e=4)
trees_2 <- trees
trees_2$plot <- "NB2"
multiple_trees <- rbind(trees, trees_2)
multiple_trees <- rbind(trees, trees %>% dplyr::mutate(plot="NB2"))
mulitple_subplots <- divide_plot(
rel_coord = multiple_plots[c("Xrel","Yrel")],
Expand Down

0 comments on commit f24f51f

Please sign in to comment.