You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言用qwraps2生成汇总表报错,请求代码排查与解决

qwraps2生成汇总表的报错排查与解决

报错1:Unexpected Symbol(处理Load_Direction时)

错误原因

在Load_Direction的统计项中存在两个语法问题:

  • 字符取值未加引号:UNLOADED、Anterior、Axial_Compression、Anterior_Axial compression都是数据中的字符型取值,必须用双引号包裹,否则R会将其视为未定义变量。
  • 带空格取值的语法错误:Anterior_Axial compression包含空格,未加引号时R会把compression识别为新的语法符号,触发"unexpected symbol"错误。

报错2:Argument 5 is empty(移除最后两个变量后)

错误原因

修改后的代码中,list的最后一个元素("Applied Load in Newtons"对应的子列表)末尾多了一个逗号,导致R判定你要传入第5个空参数,从而报错。

额外问题:变量不存在

你的原始数据中没有ATT_ACL列,代码中调用该变量会触发"object 'ATT_ACL' not found"错误,需删除该统计项或确认数据中是否存在对应变量。

修正后的完整代码

library(tidyverse)
library(readxl)
library(qwraps2)

options(qwraps2_markup = "markdown")

# 加载数据(确保文件路径正确)
ATT <- read_excel('E:/MY PROJECTS/OSTEOTOMY ACL/ATT.xlsx')
ATT_summary <-
  list( 
    "Posterior Tibial Slope (degrees)" =
      list("min"       = ~ min(PTS_Degrees, na_rm = TRUE),
           "max"       = ~ max(PTS_Degrees, na_rm = TRUE),
           "mean (sd)" = ~ qwraps2::mean_sd(PTS_Degrees, na_rm = TRUE, denote_sd = "paren")),
    "Flexion Angle" =
      list("min"       = ~ min(Flexion_Degrees, na_rm = TRUE),
           "max"       = ~ max(Flexion_Degrees, na_rm = TRUE),
           "mean (sd)" = ~ qwraps2::mean_sd(Flexion_Degrees, na_rm = TRUE, denote_sd = "paren")),
    "Applied Load in Newtons" =
      list("min"       = ~ min(Load_N, na_rm = TRUE),
           "max"       = ~ max(Load_N, na_rm = TRUE),
           "mean (sd)" = ~ qwraps2::mean_sd(Load_N, na_rm = TRUE, denote_sd = "paren")),
    "Load Direction" =
      list("Unloaded" = ~ qwraps2::n_perc0(Load_Direction == "UNLOADED"),
           "Anterior" = ~ qwraps2::n_perc0(Load_Direction == "Anterior"),
           "Axial Compression" = ~ qwraps2::n_perc0(Load_Direction == "Axial_Compression"),
           "Anterior and Axial Compression" = ~ qwraps2::n_perc0(Load_Direction == "Anterior_Axial compression")),
    "Osteotomy Type" =
      list("Native" = ~ qwraps2::n_perc0(Osteotomy_Type == "Native"),
           "AOWO"  = ~ qwraps2::n_perc0(Osteotomy_Type == "AOWO"),
           "ACWO"  = ~ qwraps2::n_perc0(Osteotomy_Type == "ACWO"),
           "MOWO"  = ~ qwraps2::n_perc0(Osteotomy_Type == "MOWO"),
           "LCWO"  = ~ qwraps2::n_perc0(Osteotomy_Type == "LCWO"))
  )

Summary_ATT_STATS <- summary_table(ATT, ATT_summary)
Summary_ATT_STATS

修正说明

  1. 给所有字符型取值添加双引号,比如"Anterior"、"Anterior_Axial compression",避免R将其识别为变量。
  2. 移除list末尾多余的逗号,消除空参数错误。
  3. 删除了不存在的ATT_ACL统计项,若数据中实际包含该列,可重新添加并确保变量名匹配。

内容的提问来源于stack exchange,提问作者Ahmed Mabrouk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 08:48:14