-
Notifications
You must be signed in to change notification settings - Fork 0
superseded: model-column metadata optimization consolidated in #169 #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -620,8 +620,8 @@ autoFIPC <- | |
| IPDItemCount <- 0 | ||
|
|
||
| # IPD target item checking | ||
| newFormColNames <- colnames(newformXDataK[colnames(newFormModel@Data$data)]) | ||
| oldFormColNames <- colnames(oldformYDataK[colnames(oldFormModel@Data$data)]) | ||
| newFormColNames <- colnames(newFormModel@Data$data) | ||
| oldFormColNames <- colnames(oldFormModel@Data$data) | ||
|
Comment on lines
+623
to
+624
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: colnames(df[cols]) equals cols here Character indexing selects columns by exact name, so Was this helpful? React with 👍 or 👎 to provide feedback.
Comment on lines
+623
to
+624
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
Rscript - <<'RS'
x <- matrix(seq_len(6), nrow = 2)
model_names <- paste0("Item.", seq_len(ncol(x)))
linked <- x[model_names]
stopifnot(is.data.frame(linked))
stopifnot(ncol(linked) == ncol(x))
RSRepository: ContextualWisdomLab/aFIPC Length of output: 208 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository guidance ---'
head -5 /tmp/coderabbit-repo-knowledge/contextualwisdomlab-afipc-649c8ab4/contextualwisdomlab-afipc-649c8ab4/*.md 2>/dev/null || true
head -5 /tmp/coderabbit-repo-knowledge/contextualwisdomlab-afipc-649c8ab4/*/*.md 2>/dev/null || true
printf '%s\n' '--- R/aFIPC.R relevant source ---'
sed -n '60,105p;360,405p;600,675p;735,765p;835,860p' R/aFIPC.R
printf '%s\n' '--- direct symbol references ---'
rg -n -C 3 'newformXDataK|oldFormColNames|newFormColNames|checkIPD|Data\$data|confirmCommonItems' R/aFIPC.RRepository: ContextualWisdomLab/aFIPC Length of output: 22852 🌐 Web query:
💡 Result: In R, a matrix is treated as an atomic vector with a dimension attribute [1]. When you use a single-argument subscript (e.g., x["Item.1"]), R attempts to subset the object as a flat vector [1]. Because a matrix has no "names" attribute by default (even if it has "dimnames"), this operation will fail or produce unexpected results if you are trying to select a column by name [1]. To select a column by name from a matrix, you must use a two-argument subscript, specifically leaving the row index empty (e.g., x[, "Item.1"]) [1][2]. Regarding the mirt package, the data argument expects a matrix or data.frame consisting of numerically ordered data [3][4]. While some users may refer to columns by name, the underlying mirt estimation functions require that the data input has appropriately defined column names if you intend to reference them or if they are to be preserved in the output [5]. If your matrix lacks column names, R's default behavior for functions like colnames is to return NULL [6]. When mirt processes unnamed matrices, it may not be able to identify specific items by name unless you explicitly assign names to the matrix columns using colnames(your_matrix) <- c(...) prior to fitting the model [5]. Summary of Key Behaviors: 1. Single Subscript on Matrix: x["Name"] treats the matrix as a flat vector and looks for the "names" attribute, not "dimnames" [1]. 2. Column Extraction: Always use x[, "ColumnName"] for matrices to target the second dimension (columns) [2][7]. 3. mirt Data Requirements: If you need to refer to items by name (e.g., in formulas or parameter identification), ensure your input matrix has non-null column names set via colnames [5]. Providing an unnamed matrix to mirt generally requires that you do not rely on item names for indexing or formula construction [3][4]. Citations:
🌐 Web query:
💡 Result: The code pattern involving Data$data and the assignment of column names like Item.1 typically appears when handling unnamed matrices in R, specifically within packages that process response data, such as the mirt package [1]. When a matrix lacks column names, R does not automatically assign them, and functions that require named columns often generate them programmatically to ensure consistency. The snippet identified from the mirt package demonstrates this common workflow [1]: if(is.null(colnames(data))) { colnames(data) <- paste0('Item.', 1L:ncol(data)) } Data$data <- data In this context: 1. The code checks if the matrix (data) has existing column names using is.null(colnames(data)) [1]. 2. If the matrix is unnamed, it generates a character vector of names in the format Item.1, Item.2, etc., using the paste0 function [1]. 3. These names are then assigned back to the matrix using colnames, ensuring that subsequent operations can reference these columns by their generated labels [1]. This approach is standard practice in data analysis pipelines in R to handle matrices that are imported without headers or metadata, allowing developers to maintain structured access to the data columns [1]. Citations: 행렬 입력을 열 부분집합 전에 정규화하세요.
IPD 및 linked-form 처리 전에 행렬 입력을 🤖 Prompt for AI AgentsSources: Coding guidelines, MCP tools |
||
|
|
||
| # ⚡ Bolt: Vectorized match() to avoid dynamic array growth overhead inside a for loop | ||
| idxNew <- match(newformCommonItemNames, newFormColNames) | ||
|
|
@@ -749,8 +749,8 @@ autoFIPC <- | |
| } | ||
| } | ||
|
|
||
| newFormColNames <- colnames(newformXDataK[colnames(newFormModel@Data$data)]) | ||
| oldFormColNames <- colnames(oldformYDataK[colnames(oldFormModel@Data$data)]) | ||
| newFormColNames <- colnames(newFormModel@Data$data) | ||
| oldFormColNames <- colnames(oldFormModel@Data$data) | ||
|
|
||
| # ⚡ Bolt: Cache parameter indices to avoid O(N) linear search inside loop | ||
| newScaleParmsItemIdxCache <- split(seq_len(nrow(NewScaleParms)), NewScaleParms$item) | ||
|
|
@@ -848,7 +848,7 @@ autoFIPC <- | |
| message('\nestimating Linked Form Eq(X) parameters') | ||
|
|
||
| # ⚡ Bolt: Cache subsetted dataframe to avoid repeated O(N) memory copies during mirt model setup | ||
| linkedFormData <- newformXDataK[colnames(newFormModel@Data$data)] | ||
| linkedFormData <- newformXDataK[newFormColNames] | ||
|
|
||
| if (forceNormalZeroOne) { | ||
| freeMEAN <- F | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ContextualWisdomLab/aFIPC
Length of output: 8048
🏁 Script executed:
Repository: ContextualWisdomLab/aFIPC
Length of output: 1426
🌐 Web query:
R base Extract.data.frame documentation duplicate column names make.unique undefined columns selected💡 Result:
In R, when subsetting a data frame using the extract operator ([), several mechanisms ensure that the resulting object maintains valid and unique column names. Duplicate Column Names and make.unique When a data frame is subsetted such that it returns another data frame, the extraction method automatically ensures that the resulting column names are unique [1][2]. If the selection process creates a situation with duplicate names—for example, if columns are selected more than once or if multiple columns with the same name are chosen—R uses the make.unique function to transform them [1][3]. The make.unique function appends sequence numbers (defaulting to the format.1,.2, etc.) to duplicate entries to distinguish them [4][5]. Undefined Columns Selected The error message "undefined columns selected" occurs when attempting to subset a data frame using column names or indices that do not exist [6][7]. A very common cause for this error is forgetting to include a comma in the subsetting expression [7]. For example, the syntax df[df$var1 > 0] is invalid because it treats the subset as a vector index, whereas df[df$var1 > 0, ] correctly specifies both rows and columns [7]. Documentation and Behavior The official R documentation for the Extract.data.frame method explicitly notes that column names are transformed to be unique if necessary during subsetting [1][8]. While data frames can be created with duplicate column names (by using check.names = FALSE), these are not preserved by many operations, including matrix-like subsetting, which will force the resulting names to be unique [9]. Top results: [1][3][7][4][9]
Citations:
colnames(df[cols])의 등가 조건을 명시하세요.cols가 고유하고 데이터프레임에 모든 열이 존재할 때만colnames(df[cols])가cols와 동일합니다. 중복 열 이름 또는 반복 선택은 결과 이름을 변경할 수 있으며, 존재하지 않는 열 이름은 오류를 발생시킵니다. 이 조건을 포함하도록 학습 노트를 수정하세요.🤖 Prompt for AI Agents
Source: MCP tools