-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate window functions in favour of {slide} #143
Comments
Awesome! Thanks for being so understanding here.
That is correct! It's all unified under the same function.
Eventually yea, after the API settles. Probably not in the first release, and yea itll probably have to live somewhere else. Still thinking through how that would work. Regarding For CRAN submission, slurrr now relies on the new dev version of vctrs, so it'll be awhile. Something that isn't in the package (I just figured out the rough version of it yesterday) is the ability to specify an # Bucket into 3 month chunks: the current month, 1 month after, 1 month before
set.seed(123)
index <- sort(yearmonth(paste0("2019-", sample(month.abb, 10, TRUE))))
index
#> [1] "2019 Feb" "2019 Mar" "2019 Mar" "2019 Apr" "2019 May" "2019 Jun"
#> [7] "2019 Jun" "2019 Sep" "2019 Oct" "2019 Nov"
slide_along_impl(index, ~.x, .index = index, .before = 1, .after = 1)
#> [[1]]
#> [1] "2019 Feb" "2019 Mar" "2019 Mar"
#>
#> [[2]]
#> [1] "2019 Feb" "2019 Mar" "2019 Mar" "2019 Apr"
#>
#> [[3]]
#> [1] "2019 Feb" "2019 Mar" "2019 Mar" "2019 Apr"
#>
#> [[4]]
#> [1] "2019 Mar" "2019 Mar" "2019 Apr" "2019 May"
#>
#> [[5]]
#> [1] "2019 Apr" "2019 May" "2019 Jun" "2019 Jun"
#>
#> [[6]]
#> [1] "2019 May" "2019 Jun" "2019 Jun"
#>
#> [[7]]
#> [1] "2019 May" "2019 Jun" "2019 Jun"
#>
#> [[8]]
#> [1] "2019 Sep" "2019 Oct"
#>
#> [[9]]
#> [1] "2019 Sep" "2019 Oct" "2019 Nov"
#>
#> [[10]]
#> [1] "2019 Oct" "2019 Nov"
# Assume these are like prices of cars, in $
# Bucket them into ranges of: current price, $5000 before, $5000 after
set.seed(123)
index <- sort(rnorm(10, mean = 50000, sd = 5000))
index
#> [1] 43674.69 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44
#> [8] 52304.58 57793.54 58575.32
slide_along_impl(index, ~.x, .index = index, .before = 5000, .after = 5000)
#> [[1]]
#> [1] 43674.69 46565.74 47197.62 47771.69
#>
#> [[2]]
#> [1] 43674.69 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44
#>
#> [[3]]
#> [1] 43674.69 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44
#>
#> [[4]]
#> [1] 43674.69 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44 52304.58
#>
#> [[5]]
#> [1] 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44 52304.58
#>
#> [[6]]
#> [1] 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44 52304.58
#>
#> [[7]]
#> [1] 46565.74 47197.62 47771.69 48849.11 50352.54 50646.44 52304.58
#>
#> [[8]]
#> [1] 47771.69 48849.11 50352.54 50646.44 52304.58
#>
#> [[9]]
#> [1] 57793.54 58575.32
#>
#> [[10]]
#> [1] 57793.54 58575.32 |
Thanks. When I try to install
Do you have any idea how to solve this? Based on the current tsibble::slide_dbl(1:5, mean, .size = 2)
#> [1] NA 1.5 2.5 3.5 4.5
tsibble::slide_dbl(1:5, mean, .size = 3, .align = "center")
#> [1] NA 2 3 4 NA Created on 2019-08-19 by the reprex package (v0.3.0) |
Sorry, had something out of sync. Try again? Also, docs will get better, but here is how I think about the API: tsibble::slide_dbl(1:5, mean, .size = 2)
#> [1] NA 1.5 2.5 3.5 4.5
# "1 row before the current row, to 0 rows after the current row"
slurrr::slide_dbl(1:5, mean, .before = 1)
#> [1] 1.0 1.5 2.5 3.5 4.5
# + only complete windows
slurrr::slide_dbl(1:5, mean, .before = 1, .complete = TRUE)
#> [1] NA 1.5 2.5 3.5 4.5
tsibble::slide_dbl(1:5, mean, .size = 3, .align = "center")
#> [1] NA 2 3 4 NA
# "1 row before the current row, to 1 row after the current row"
slurrr::slide_dbl(1:5, mean, .before = 1, .after = 1, .complete = TRUE)
#> [1] NA 2 3 4 NA Created on 2019-08-19 by the reprex package (v0.2.1) It's a fairly direct translation from SQL window functions, so hopefully people familiar with that will instantly understand. After using it for awhile, I find it a bit easier to understand than the alignment argument (and obviously its a bit more flexible). This is a nice intro to the ideas https://dbplyr.tidyverse.org/articles/translation-function.html#window-functions |
Thanks. The installation is resolved now. If "the current row" is rephrased to "the anchor point", Do you have plan for the tsibble::slide_dbl(1:5, mean, .size = 2, .fill = NULL)
#> [1] 1.5 2.5 3.5 4.5 Perhaps I also keep thinking cumulative sliding is to use The |
I'm still not sure what the right default is. I feel like when I was a practitioner I always was setting
I think that for
I thought about this a lot and it essentially came down to the fact that I don't think saying you want "infinite values before the current element" makes much sense (plus yea the library(slide)
x <- 1:5
# simulate infinity
# this is fine
slide::slide(x, ~.x, .before = 9999999)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 1 2 3
#>
#> [[4]]
#> [1] 1 2 3 4
#>
#> [[5]]
#> [1] 1 2 3 4 5
# (simulate infinity, you can never create a "complete" window
# with infinite values before the current one)
slide::slide(x, ~.x, .before = 9999999, .complete = TRUE)
#> [[1]]
#> NULL
#>
#> [[2]]
#> NULL
#>
#> [[3]]
#> NULL
#>
#> [[4]]
#> NULL
#>
#> [[5]]
#> NULL
# unbounded() is more like saying "pin the starting value of the window to the
# first value of `x`
slide::slide(x, ~.x, .before = unbounded(), .complete = TRUE)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 1 2 3
#>
#> [[4]]
#> [1] 1 2 3 4
#>
#> [[5]]
#> [1] 1 2 3 4 5 Created on 2019-08-23 by the reprex package (v0.2.1) The SQL bits might come into play with |
Pinging @robjhyndman, can you share your experience here? Which one do you use more often in practice, complete or partial sliding? Regarding the deprecation process, it will not start until the |
In |
@robjhyndman The default in |
I would normally use |
cc @DavisVaughan
I'd be happy to deprecate window functions in favour of
slurrr::slide()
. I've had a quick look, and seems thatslurrr::slide()
replaceslide()
,tile()
,stretch()
all together by using different parameters?You'll probably have
future_slide()
in mind too? living inslurrr
orfurrr
?Looks like https://github.com/r-lib/funs also plans to implement this set of functions. But Hadley said no plan in the near future. Does it mean
slurrr
will not be replaced byfuns
?What timeline do you think for submitting to CRAN?
The text was updated successfully, but these errors were encountered: