So currently the validation for xmap_df format is somewhat fragile, because a user could create an xmap_df and then modify it using standard data.frame or dplyr operations:
it would be quite hard to detect these modifications in downstream functions like apply_xmap() #95, meaning you'd probably have to redo the weight validation again later on.
If however, you had a list class like xmap_list it would be more difficult to mess up weights etc., and you could in theory just do a class check. Still, there's probably no getting around re-validating the df at the transformation step.
> class(xmap) <- c("xmap_list", "xmap")
> xmap
$x
[1] "a" "b" "c" "d" "e"
$y
[1] 1 2 3 4 5
$z
[1] 0.93499353 0.30061182 0.29352285 0.17409116 0.06566421
attr(,"class")
[1] "xmap_df" "xmap"
attr(,"row.names")
[1] 1 2 3 4 5
attr(,"col_from")
[1] "x"
attr(,"col_to")
[1] "y"
attr(,"col_weights")
[1] "z"
attr(,"from_set")
[1] "a" "b" "c" "d" "e"
> xmap |> dplyr::mutate(x = 5)
Error in UseMethod("mutate") :
no applicable method for 'mutate' applied to an object of class "c('xmap_list', 'xmap')"
So currently the validation for
xmap_df
format is somewhat fragile, because a user could create anxmap_df
and then modify it using standard data.frame ordplyr
operations:it would be quite hard to detect these modifications in downstream functions like
apply_xmap()
#95, meaning you'd probably have to redo the weight validation again later on.If however, you had a list class like
xmap_list
it would be more difficult to mess up weights etc., and you could in theory just do a class check. Still, there's probably no getting around re-validating the df at the transformation step.