Skip to content

Commit cd9c4ef

Browse files
committed
fix cov input bug
1 parent 8b4a1ca commit cd9c4ef

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

R/principalcomponentanalysis.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
7878
return(dataset)
7979
}
8080

81+
# it seems the column names are sorted alphabetically when all columns are read
82+
# so we need to sort the column names to match the order of the variables
83+
sortedIndices <- sort(as.numeric(gsub(".*_(\\d+)_.*", "\\1", colnames(dataset))))
84+
sortedNames <- paste0("JaspColumn_", sortedIndices, "_Encoded")
85+
dataset <- dataset[, sortedNames]
86+
8187
# possible data matrix?
8288
if ((nrow(dataset) != ncol(dataset)))
8389
.quitAnalysis(gettext("Input data does not seem to be a square matrix! Please check the format of the input data."))
@@ -87,6 +93,7 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
8793

8894
usedvars <- unlist(options[["variables"]])
8995
var_idx <- match(usedvars, colnames(dataset))
96+
9097
mat <- try(as.matrix(dataset[var_idx, var_idx]))
9198
if (inherits(mat, "try-error"))
9299
.quitAnalysis(gettext("All cells must be numeric."))
@@ -102,10 +109,11 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, ..
102109
.quitAnalysis("Not enough valid columns to run this analysis")
103110
}
104111
}
112+
113+
105114
return(mat)
106115
}
107116

108-
109117
.pcaCheckErrors <- function(dataset, options) {
110118

111119
customChecksPCAEFA <- list(

0 commit comments

Comments
 (0)