# styler: off
x <- tribble(
~gx, ~gy,
0, 0,
50, 25,
999.9, 499.95,
1000, 500
)
# styler: on
# `gridsize` has a common default; `plotdim` is guessed from the data
add_lxly(x)
gridsize <- 20
plotdim <- c(1000, 500)
add_qxqy(x, gridsize, plotdim)
add_index(x, gridsize, plotdim)
add_hectindex(x, gridsize, plotdim)
add_quad(x, gridsize, plotdim)
add_quad(x, gridsize, plotdim, start = 0)
# `width` gives the nuber of digits to pad the label of plot-rows and
# plot-columns, e.g. 3 pads plot-rows with three zeros and plot-columns with
# an extra trhree zeros, resulting in a total of 6 zeros.
add_quad(x, gridsize, plotdim, start = 0, width = 3)
add_col_row(x, gridsize, plotdim)
# From `quadrat` or `QuadratName` --------------------------------------
# styler: off
x <- tribble(
~QuadratName,
"0001",
"0011",
"0101",
"1001"
)
# styler: on
# Output `gx` and `gy` ---------------
add_gxgy(x)
assert_is_installed("fgeo.x")
# Warning: The data may already have `gx` and `gx` columns
gxgy <- add_gxgy(fgeo.x::tree5)
select(gxgy, matches("gx|gy"))
# Output `col` and `row` -------------
# Create columns `col` and `row` from `QuadratName` with `tidyr::separate()`
# The argument `sep` lets you separate `QuadratName` at any positon
if (FALSE) {
tidyr_is_installed <- requireNamespace("tidyr", quietly = TRUE)
stringr_is_installed <- requireNamespace("stringr", quietly = TRUE)
if (tidyr_is_installed && stringr_is_installed) {
library(tidyr)
library(stringr)
vft <- tibble(QuadratName = c("0001", "0011"))
vft
separate(
vft,
QuadratName,
into = c("col", "row"),
sep = 2
)
census <- select(fgeo.x::tree5, quadrat)
census
census$quadrat <- str_pad(census$quadrat, width = 4, pad = 0)
separate(
census,
quadrat,
into = c("col", "row"),
sep = 2,
remove = FALSE
)
}
}
Run the code above in your browser using DataLab