These functions are intended to be used in new metric extensions.
They handle subset_sf
data (inherited from sf
class) stored in
segmetric
objects.
sm_list()
lists subsets already computed and stored in asegmetric
object.sm_exists()
verifies if asubset_id
exists in asegmetric
object.sm_subset()
evaluates and stores asubset_sf
object.sm_indirect()
finds thesubset_id
of a givensubset_sf
object stored in asegmetric
object.sm_segmetric()
returns thesegmetric
object that stores a givensubset
object (either aref_sf
, aseg_sf
, or asubset_sf
).sm_get()
retrieves asubset_sf
object stored in asegmetric
object.sm_inset()
operator equivalent to inner join but returns only objects froms1
, or its corresponding row ins2
if parameterreturn_index
isTRUE
.sm_group_by()
: Apply a function to groups ofsubset_sf
.
Usage
sm_list(m)
sm_exists(m, subset_id)
sm_subset(m, subset_id, expr = NULL)
sm_indirect(s)
sm_segmetric(s)
sm_get(m, subset_id)
sm_ref(m)
sm_seg(m)
sm_inset(s1, s2, return_index = FALSE)
# S3 method for ref_sf
sm_inset(s1, s2, return_index = FALSE)
# S3 method for seg_sf
sm_inset(s1, s2, return_index = FALSE)
# S3 method for subset_sf
sm_inset(s1, s2, return_index = FALSE)
sm_group_by(s, by, fn, ...)
Arguments
- m
A
segmetric
object.- subset_id
A
character
value informing a subset name.- expr
A valid piece of code in R inside curly braces. This code is evaluated to generate a subset.
- s, s1, s2
Either a
ref_sf
, aseg_sf
, or asubset_sf
object.- return_index
A
logical
value indicating if the corresponding rows ins1
should be returned instead of the actual corresponding values ofs2
.- by
A
character
value with the column to group.- fn
A
function
to apply on each group.- ...
For
sm_group_by()
, extra parameter to pass tofn
function.
Value
sm_list()
: Return acharacter
vector with all names of subsets stored in thesegmetric
object.sm_exists()
: Return alogical
value indicating if a given subset name is stored in thesegmetric
object.sm_subset()
: Return asubset_sf
object.sm_indirect()
: Return the subset name of a givensubset_sf
object stored in asegmetric
object.sm_segmetric()
: Return asegmetric
object that stores a givensubset_sf
object.sm_get()
: Return asubset_sf
object stored in asegmetric
object.sm_inset()
: Return either asubset_sf
object or aninteger
vector with the index of corresponding rows ofs2
object.sm_group_by()
: Return asubset_sf
object.
Examples
# load sample datasets
data("sample_ref_sf", package = "segmetric")
data("sample_seg_sf", package = "segmetric")
# create segmetric object
m <- sm_read(ref_sf = sample_ref_sf, seg_sf = sample_seg_sf)
# lists only 'ref_sf' and 'seg_sf'
sm_list(m)
#> [1] "ref_sf" "seg_sf"
# computes 'Y_tilde' subset and stores it as 'test_subset' subset id
# sm_ytilde(m) also stores a subset under 'Y_tilde' id
s <- sm_subset(m, "test_subset", sm_ytilde(m))
# lists 'ref_sf', 'seg_sf', 'test_subset', and 'Y_tilde'
sm_list(m)
#> [1] "Y_tilde" "ref_sf" "seg_sf" "test_subset"
# which segmetric object stores `s` subset?
m2 <- sm_segmetric(s)
# m is identical to m2
identical(m, m2)
#> [1] TRUE
# which name `s` subset is stored in `m` segmetric object?
sm_indirect(s)
#> [1] "test_subset"
# retrieve 'test_subset' data from `m` object
s2 <- sm_get(m, 'test_subset')
# s is identical to s2
identical(s, s2)
#> [1] TRUE