You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As demonstrated in the reprex below, the features.tbl_ts() fails when .var is a character string. Wrapping this function with a variable column name is a problem.
library(fabletools)
library(tsibble)
#> #> Attaching package: 'tsibble'#> The following objects are masked from 'package:base':#> #> intersect, setdiff, union
head(tourism, 160) |>
features(Trips, features=list(mean=mean, sd=sd))
#> # A tibble: 2 × 5#> Region State Purpose mean sd#> <chr> <chr> <chr> <dbl> <dbl>#> 1 Adelaide South Australia Business 156. 35.6#> 2 Adelaide South Australia Holiday 157. 27.1
head(tourism, 160) |>
features("Trips", features=list(mean=mean, sd=sd))
#> Warning in mean.default(...): argument is not numeric or logical: returning NA#> Warning in mean.default(...): argument is not numeric or logical: returning NA#> Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm =#> na.rm): NAs introduced by coercion#> Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm =#> na.rm): NAs introduced by coercion#> # A tibble: 2 × 5#> Region State Purpose mean sd#> <chr> <chr> <chr> <dbl> <dbl>#> 1 Adelaide South Australia Business NA NA#> 2 Adelaide South Australia Holiday NA NAfoo<-function(df, col_name) {
df|>
features(!!rlang::enquo(col_name), features=list(mean=mean, sd=sd))
}
head(tourism, 160) |>
foo(Trips)
#> # A tibble: 2 × 5#> Region State Purpose mean sd#> <chr> <chr> <chr> <dbl> <dbl>#> 1 Adelaide South Australia Business 156. 35.6#> 2 Adelaide South Australia Holiday 157. 27.1
head(tourism, 160) |>
foo("Trips")
#> Warning in mean.default(...): argument is not numeric or logical: returning NA#> Warning in mean.default(...): argument is not numeric or logical: returning NA#> Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm =#> na.rm): NAs introduced by coercion#> Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm =#> na.rm): NAs introduced by coercion#> # A tibble: 2 × 5#> Region State Purpose mean sd#> <chr> <chr> <chr> <dbl> <dbl>#> 1 Adelaide South Australia Business NA NA#> 2 Adelaide South Australia Holiday NA NA
features() allows for calculation of features from arbitrary expressions, and so "Trips" is handled as a length 1 character vector.
To select columns with tidyselect you can use features_at().
E.g.
library(fabletools)
library(tsibble)
#> #> Attaching package: 'tsibble'#> The following objects are masked from 'package:base':#> #> intersect, setdiff, union
head(tourism, 160) |>
features(Trips, features=list(mean=mean, sd=sd))
#> # A tibble: 2 x 5#> Region State Purpose mean sd#> <chr> <chr> <chr> <dbl> <dbl>#> 1 Adelaide South Australia Business 156. 35.6#> 2 Adelaide South Australia Holiday 157. 27.1
head(tourism, 160) |>
features_at("Trips", features=list(mean=mean, sd=sd))
#> # A tibble: 2 x 5#> Region State Purpose Trips_mean Trips_sd#> <chr> <chr> <chr> <dbl> <dbl>#> 1 Adelaide South Australia Business 156. 35.6#> 2 Adelaide South Australia Holiday 157. 27.1
As demonstrated in the reprex below, the
features.tbl_ts()
fails when.var
is a character string. Wrapping this function with a variable column name is a problem.Created on 2023-07-21 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: