'R: Anomalize Input `..1` must be of size 8 or 1, not size 0
I am trying to use the Anomalize package in R to do anomaly detection on data pulled from a MySQL database based on the timestamp.
The error that I'm running into is
Error: Problem with `filter()` input `..1`.
i Input `..1` is `time_scale == key_value`.
x Input `..1` must be of size 8 or 1, not size 0.
Backtrace:
x
1. +-`%>%`(...)
2. +-anomalize::plot_anomalies(...)
3. +-anomalize::time_recompose(.)
4. +-anomalize::anomalize(., remainder)
5. +-anomalize::time_decompose(., temp)
6. +-anomalize:::time_decompose.tbl_df(., temp)
7. | +-anomalize::time_decompose(...)
8. | \-anomalize:::time_decompose.tbl_time(...)
9. | \-`%>%`(...)
10. +-anomalize::decompose_stl(...)
11. | \-anomalize::time_frequency(data, period = frequency, message = message)
12. | \-`%>%`(...)
13. +-anomalize:::target_time_decomposition_scale(...)
14. | \-template %>% dplyr::filter(time_scale == key_value) %>% dplyr::pull(!!target_expr)
15. +-dplyr::pull(., !!target_expr)
16. +-dplyr::filter(., time_scale == key_value)
17. +-dplyr:::filter.data.frame(., time_scale == key_value)
18. | \-dplyr:::filter_rows(.data, ..., caller_env = caller_env())
19. | +-base::withCallingHandlers(...)
20. | \-mask$eval_all_filter(dots, env_filter)
21. +-dplyr:::abort_glue(...)
22. | +-rlang::exec(abort, message = message, class = class, !!!data)
23. | \-(function (message = NULL, class = NULL, ..., trace = NULL, parent = NULL, ...
24. | \-rlang:::signal_abort(cnd)
25. | \-base::signalCondition(cnd)
26. \-(function (e) ...
This is the code that is having this issue
#Convert string to datetime data format
data$timestamp <- as.POSIXct(data$timestamp, format="%Y-%m-%d %H:%M:%S", tz=Sys.timezone())
data %>%
as_tibble() %>%
# Error starts here
time_decompose(value) %>%
anomalize(remainder) %>%
time_recompose() %>%
# Anomaly Visualization
plot_anomalies(time_recomposed = TRUE, ncol = 3, alpha_dots = 0.25) +
labs(title = "Anomalies", subtitle = "Anomaly")
The weirdest issue here is that I am only getting the error for data that was inserted into the database in the afternoon. I have tested a few sets of data with different timestamps and all data collected in the morning works fine while data collected in the afternoon gives an error.
Data that anomalize works fine with
# A tibble: 16,146 x 8
id timestamp value
<int> <dttm> <dbl>
1 162254 2022-01-12 10:28:39.000000 0
2 162255 2022-01-12 10:28:42.000000 25.3
3 162256 2022-01-12 10:28:44.000000 25.3
4 162257 2022-01-12 10:28:45.000000 25.3
5 162258 2022-01-12 10:28:46.000000 25.3
6 162259 2022-01-12 10:28:47.000000 25.3
7 162260 2022-01-12 10:28:49.000000 25.3
8 162261 2022-01-12 10:28:50.000000 25.2
9 162262 2022-01-12 10:28:51.000000 25.3
10 162263 2022-01-12 10:28:52.000000 25.3
# ... with 16,136 more rows
Data that anomalize does not like
# A tibble: 15,164 x 8
id timestamp value
<int> <dttm> <dbl>
1 147090 2022-01-11 13:30:20.000000 0
2 147091 2022-01-11 13:30:25.000000 24.7
3 147092 2022-01-11 13:30:27.000000 24.7
4 147093 2022-01-11 13:30:28.000000 24.7
5 147094 2022-01-11 13:30:30.000000 24.7
6 147095 2022-01-11 13:30:32.000000 24.7
7 147096 2022-01-11 13:30:33.000000 24.7
8 147097 2022-01-11 13:30:34.000000 24.7
9 147098 2022-01-11 13:30:36.000000 24.7
10 147099 2022-01-11 13:30:37.000000 24.7
# ... with 15,154 more rows
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
