如何解决R dplyr 的持久变异状态持续抛出错误,直到 R 重新启动
我遇到了一个无法重现但我有控制台和视频录制的超级奇怪的错误。基本上,在抛出一个
时发生变异Error: Problem with `mutate()` input `..2`.
x subscript out of bounds
ℹ Input `..2` is `(function (.cols = everything(),.fns = NULL,...,.names = NULL) ...`.
似乎有一个持久状态。在下面的代码块中,您可以看到
- 我加载数据并成功运行了一段 mutate 代码
- 我在 Shiny 应用程序中打开并收到 mutate 错误,然后关闭应用程序
- 具有重新加载数据的相同原始代码现在抛出相同的变异错误,而它之前成功运行!
- 我运行了一个不相关的 mutate,它不会影响成功运行的原始数据
- 我现在第三次重新加载数据,代码现在再次成功运行!
!我不知道是什么导致了这种情况,显然很难重现。这是一些控制台输出,显示了我的意思
# CODE RUNS SUCCESSFULLY FIRST TIME
> df_error <- read_rds('df_error.rds')
> return_data <- df_error %>%
+ dplyr::mutate(
+ new_hour = paste0(hour,':00'),+ across(c(contains('notional'),buy_pool,net_buy_delta,-net_notional_percent_change),scales::label_dollar()),+ across(c(contains('percent'),contains('concentration')),scales::label_percent(accuracy=.1))
+ )
# START SHINY APP AND GET ERROR
> shiny::runApp('position_limit_engine')
Loading required package: shiny
Attaching package: ‘shiny’
The following objects are masked from ‘package:DT’:
dataTableOutput,renderDataTable
Attaching package: ‘plotly’
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
The following object is masked from ‘package:ggplot2’:
last_plot
Listening on http://127.0.0.1:7094
[1] 12
Warning in mean.default(hour) :
argument is not numeric or logical: returning NA
Warning in mean.default(hour) :
argument is not numeric or logical: returning NA
Warning: Error in : Problem with `mutate()` input `..2`.
x subscript out of bounds
ℹ Input `..2` is `(function (.cols = everything(),.names = NULL) ...`.
135: <Anonymous>
# SAME CODE NOW ALSO THROWS ERROR
> df_error <- read_rds('df_error.rds')
> return_data <- df_error %>%
+ dplyr::mutate(
+ new_hour = paste0(hour,scales::label_percent(accuracy=.1))
+ )
Error: Problem with `mutate()` input `..2`.
x subscript out of bounds
ℹ Input `..2` is `(function (.cols = everything(),.names = NULL) ...`.
Run `rlang::last_error()` to see where the error occurred.
# RUN UNRELATED MUTATE THAT WORKS AND DOESN'T MODIFY ORIGINAL DATAFRAME
> df_error %>%
+ dplyr::mutate(
+ # hour = paste0(hour,scales::label_percent(accuracy=.1))
+ )
# A tibble: 3 x 21
limit market period hour num_stocks net_notional_pr… net_notional_new net_notional_de… net_notional_pe… concentration_p… concentration_n…
* <fct> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr>
DATA
# … with 10 more variables: concentration_delta <chr>,concentration_buys_prev <chr>,concentration_buys_new <chr>,# concentration_buys_delta <chr>,affected_users <dbl>,affected_percentage_buyers <chr>,buy_pool <chr>,net_buy_percent_change <chr>,# net_buy_delta <chr>,net_buy_pool_percent_change <chr>
# CODE NOW RUNS SUCCESSFULLY AGAIN
> df_error <- read_rds('df_error.rds')
> return_data <- df_error %>%
+ dplyr::mutate(
+ new_hour = paste0(hour,scales::label_percent(accuracy=.1))
+ )
> View(return_data)
有人知道会发生什么吗?很抱歉无法获得可重现的条件,但我更想了解可能导致这种情况的原因。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。