File: formula-utils.R

package info (click to toggle)
r-cran-mclogit 0.9.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Deparse into a single string
deparse0 <- function(formula) paste(trimws(deparse(formula)),collapse=" ")

# Concatenate two formulae
c_formulae <- function(formula,extra){
    formula.deparsed <- deparse0(formula)
    extra.deparsed <- sub("~","+",deparse0(extra)) 
    as.formula(paste(formula.deparsed,
                     extra.deparsed),
               env=environment(formula))
}

# Check if formula
is_formula <- function(x)inherits(x,"formula")

# Subtitute "|" with "+"
random2formula <- function(r) {
    formula.deparsed <- deparse0(r$formula)
    gf <- paste(r$groups,collapse="+")
    as.formula(paste(formula.deparsed,
                     gf,sep="+"),
               env=environment(r$formula))
}