R/tool_detect_colnames.R

Defines functions .detect_colnames

.detect_colnames <- function(data, prefix) {
  
  # 1. 获取所有列名
  all_names <- names(data)
  
  # 2. 使用 startsWith 匹配前缀
  matched_cols <- all_names[startsWith(all_names, prefix)]
  
  # 3. 错误处理
  # nocov start
  if (length(matched_cols) == 0L) {
    stop(
      "Could not automatically detect columns with prefix '", prefix, 
      "'. Please manually specify column names."
    )
  }
  # nocov end
  return(matched_cols)
}

Try the multiRL package in your browser

Any scripts or data that you put into this service are public.

multiRL documentation built on March 31, 2026, 5:06 p.m.