tidyfun / tf

S3 classes and methods for tidy functional data
https://tidyfun.github.io/tf/
GNU Affero General Public License v3.0
7 stars 2 forks source link

constructing `tfd` vectors with length 1 #138

Closed m-muecke closed 4 days ago

m-muecke commented 2 weeks ago

Constructing tf and tfb vectors with length one fail due to the domain assertion, but not for length equal or greater than 2. @fabian-s I think we should either allow length one vectors or throw a more informative error. Since zero length vectors are allowed I would argue length 1 vectors need to be supported as well.

tf::tfd(1)
#> Error in new_tfd(arg, datalist, regular, domain, evaluator): Assertion on 'domain' failed: Contains duplicated values, position 2.
tf::tfd(1:2)
#> tfd[1] on (1,2) based on 2 evaluations each
#> interpolation by tf_approx_linear 
#> [1]: (1,1);(2,2)
tf::tfb(1)
#> Error in new_tfb_spline(data, domain = domain, penalized = penalized, : Assertion on 'domain' failed: Contains duplicated values, position 2.
tf::tfb(1:2)
#> Warning in smooth.construct.cr.smooth.spec(s_spec, data = data_frame(arg = arg_u$x, : basis dimension, k, increased to minimum possible
#> Error in smooth.construct.cr.smooth.spec(s_spec, data = data_frame(arg = arg_u$x, : arg has insufficient unique values to support 3 knots: reduce k.

Created on 2024-11-10 with reprex v2.1.1

fabian-s commented 2 weeks ago

I think we should either allow length one vectors or throw a more informative error. Since zero length vectors are allowed I would argue length 1 vectors need to be supported as well.

Agreed. domain then set to the value itself.

does that need "cli_inform" like for the empty prototype as well?

tf::tfd()
#> Input `data` not recognized class; returning prototype of length 0.
#> tfd[0] on (0,0) based on 0 evaluations each
#> interpolation by tf_approx_linear 
m-muecke commented 2 weeks ago

I think we should either allow length one vectors or throw a more informative error. Since zero length vectors are allowed I would argue length 1 vectors need to be supported as well.

Agreed. domain then set to the value itself.

does that need "cli_inform" like for the empty prototype as well?

tf::tfd()
#> Input `data` not recognized class; returning prototype of length 0.
#> tfd[0] on (0,0) based on 0 evaluations each
#> interpolation by tf_approx_linear 

I would argue the message should be removed for empty prototypes, then it also aligns more closely with other packages, furthemore tfb() also doesn't provide a message for empty prototypes.

fabian-s commented 2 weeks ago

alright, good point. let's do that then.