Created
September 1, 2023 09:52
-
-
Save tslumley/d8d6f154e2f8b767124e35a4b205ed35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paired_test<-function(formula, data, subset, paired=NULL, ...){ | |
if (is.null(paired)) | |
return("do the current thing") | |
## make sure paired is ~id | |
if (!is.language(paired)) | |
stop("paired must be a formula") | |
if(!(length(paired)==2 && paired[[1L]]=="~" && length(paired[[2L]])<=2)) | |
stop("paired must be a one-sided formula") | |
## get id | |
id <- match.call(expand.dots = FALSE) | |
id$formula<-id$paired | |
id$paired<-NULL | |
if (is.matrix(eval(id$data, parent.frame()))) | |
id$data <- as.data.frame(data) | |
id$na.action<-"na.pass" | |
id[[1L]] <- quote(stats::model.frame) | |
id$... <- NULL | |
mf_id <- eval(id, parent.frame()) | |
## get data | |
m <- match.call(expand.dots = FALSE) | |
if (is.matrix(eval(m$data, parent.frame()))) | |
m$data <- as.data.frame(data) | |
m[[1L]] <- quote(stats::model.frame) | |
m$... <- m$paired<- NULL | |
m$na.action<-"na.pass" | |
mf <- eval(m, parent.frame()) | |
DNAME <- paste(names(mf), collapse = " by ") | |
names(mf) <- NULL | |
response <- attr(attr(mf, "terms"), "response") | |
return(cbind(mf, mf_id)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment