Skip to content

Instantly share code, notes, and snippets.

@tslumley
Created September 1, 2023 09:52
Show Gist options
  • Save tslumley/d8d6f154e2f8b767124e35a4b205ed35 to your computer and use it in GitHub Desktop.
Save tslumley/d8d6f154e2f8b767124e35a4b205ed35 to your computer and use it in GitHub Desktop.
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