`tab_multi_manager()` fails with a named character vector

未关闭 适合新手
#67 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
73/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
r
领域
backend

调研方向

问题出在 summarize_secret() 中,其中 var 在 dplyr::rename_with() 内传递给 dplyr::all_of();issue 没有指出源文件或测试。找到该函数,并使用类似 c(variableInteret = "EMPL") 的命名值复现此调用。对于有名称的字符向量,相应列能够无错误地重命名为 VALUE,且现有的无名称输入仍能正常工作,即为完成。

由索引模型根据 Issue 内容生成。

描述

bug

Bug: tab_multi_manager() fails with a named character vector in previously working processing pipelines

Description

A call to tab_multi_manager() fails in summarize_secret() when the value argument is a named character vector rather than an unnamed character string.

This issue did not occur with previous versions: existing processing pipelines that previously ran successfully now fail with the error described below.

For example, cluster[[1]]$nomVarValue may contain:

c(variableInteret = "EMPL")

rather than:

"EMPL"

The names attribute of the vector causes dplyr::rename_with() to fail when var is passed to all_of(var).

Steps to reproduce

liste_tbx_res <- tab_multi_manager(
  list_tables = lTables,
  list_explanatory_vars = lVars,
  alt_hrc = lHrc,
  alt_totcode = lTotaux,
  value = cluster[[1]]$nomVarValue,
  freq = cluster[[1]]$nomVarFreq,
  dir_name = file.path(
    getOption("rtauargus.tauargus_output"),
    sNomcluster
  ),
  cost_var = "cost_var",
  secret_no_pl = "secret_no_pl"
)

When cluster[[1]]$nomVarValue is a named character vector, the call fails with the following error:

Error in `purrr::map()`:
i In index: 1.
i With name: ape_EMPL_ceff7.

Caused by error in `dplyr::rename_with()`:
! Can't rename variables in this context.

The error originates from the following code in summarize_secret():

res_tau %>%
  {
    if (!is.null(var)) {
      dplyr::rename_with(., ~ "VALUE", dplyr::all_of(var))
    } else {
      .
    }
  }

Expected behavior

The function should continue to accept the named character vectors produced by existing processing pipelines and rename the corresponding column to VALUE without raising an error.

Actual behavior

Processing pipelines that worked with previous versions now fail in dplyr::rename_with() when var retains its names attribute.

Proposed fix

Remove the names attribute before passing var to all_of():

res_tau %>%
  {
    if (!is.null(var)) {
      dplyr::rename_with(., ~ "VALUE", dplyr::all_of(unname(var)))
    } else {
      .
    }
  }

Alternatively, normalize var at the beginning of summarize_secret():

if (!is.null(var)) {
  var <- unname(var)
}

Additional information

The issue is resolved by passing unname(value) instead of value to summarize_secret(). The underlying variable name ("EMPL") is valid; the problem appears to be related to the vector's names attribute.

This is a regression affecting existing processing pipelines that worked with previous versions. The version in which the behavior changed remains to be identified.

主要语言
HTML
星标
12
派生
6
平均合并
36 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

InseeFrLab/rtauargus 的其他 Issue

查看 InseeFrLab/rtauargus 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。