4545# ' @export
4646jaspFormula <- function (formula , data ) {
4747 formulaEncoded <- formulaEncode(formula )
48- data <- formulaCheckOrReadData(data )
49- formulaCheckRequirements(formulaEncoded , data )
48+
49+ colNames <- formulaCheckOrReadData(data )
50+ formulaCheckRequirements(formulaEncoded , colNames )
5051
5152 # TODO: We should use the encoded formula hier, but if a column has a type ('col.scale'), then it is decoded by 'col'
5253 result <- list (
@@ -63,7 +64,6 @@ jaspFormula <- function(formula, data) {
6364# ' @rdname jaspFormula
6465# ' @export
6566makeJaspFormula <- function (... , response = NULL , data ) {
66- data <- formulaCheckOrReadData(data )
6767
6868 if (! is.null(response ) && ! is.character(response )) {
6969 stop(" `response` must be a character." , domain = NA )
@@ -78,7 +78,7 @@ makeJaspFormula <- function(..., response=NULL, data) {
7878 }
7979
8080
81- rhs <- vapply(dots , makeJaspFormulaRhs , character (1 ), data = data )
81+ rhs <- vapply(dots , makeJaspFormulaRhs , character (1 ))
8282
8383 formula <- stats :: reformulate(rhs , response )
8484 return (jaspFormula(formula , data ))
@@ -94,8 +94,7 @@ jaspFormulaRhs <- function(terms = NULL, group = NULL, intercept = TRUE, correla
9494 return (result )
9595}
9696
97- makeJaspFormulaRhs <- function (rhs , data ) {
98- allVarNames <- colnames(data )
97+ makeJaspFormulaRhs <- function (rhs ) {
9998
10099 result <- paste(rhs [[" terms" ]], collapse = " +" )
101100 if (is.null(rhs [[" terms" ]])) {
@@ -133,27 +132,26 @@ formulaEncode <- function(formula) {
133132
134133formulaCheckOrReadData <- function (data ) {
135134 # If we are in JASP and no data are supplied explicitly, we simply read the dataset from JASP.
136- if (jaspBase :: jaspResultsCalledFromJasp()) # && (missing(data) || is.null(data)))
135+ if (jaspBase :: jaspResultsCalledFromJasp()) {
137136 data <- jaspBase :: readDataSetToEnd(all.columns = TRUE )
137+ colNames = decodeColNames(colnames(data ))
138+ } else {
139+ colNames = jaspSyntax :: getVariableNames()
140+ }
138141
139- if (missing(data ) || is.null(data ) || ! is.data.frame(data ))
140- stop(" `data` must be a data frame." , domain = NA )
141-
142- return (data )
142+ return (colNames )
143143}
144144
145- formulaCheckRequirements <- function (formula , data ) {
145+ formulaCheckRequirements <- function (formula , columnNames ) {
146146 if (! inherits(formula , " formula" )) {
147147 stop(" `formula` argument must be object of class `formula`." , domain = NA )
148148 }
149-
150149 attr <- attributes(stats :: terms(formula ))
151150
152151 if (! is.null(attr [[" offset" ]])) {
153152 stop(" JASP formulas do not understand `offset` terms. Analyses that allow the `offset` terms have a special `offset` argument." , domain = NA )
154153 }
155154
156- columnNames <- decodeColNames(colnames(data ))
157155 lhs <- decodeColNames(all.names(formulaExtractLhs(formula )))
158156 anyLhsTransformed <- ! all(lhs %in% c(columnNames , " cbind" , " (" , " )" ))
159157
0 commit comments