Learn R Programming

lavaan (version 0.7-2)

open_parser: The open parser configuration

Description

The lavaan model syntax parser can be extended with new operators, modifiers and groupings. These extensions are only used in the 'open' parser.

Usage

lav_parse_options(
    pkgname   = NULL,
    operators = NULL,
    modifiers = NULL,
    groupings  = NULL
  )

Value

A list with data.frames containing the currently active parser configuration.

Arguments

pkgname

The name of the package that extends the elements.

operators

A character vector with new operators. These operators must start and end with a percentage sign and be at least 3 characters long.

modifiers

A data.frame with columns mod, side and expect. The elements in mod must be character strings in snake_case. The elements in side must be l or r, indicating whether the modifier is expected on the left-hand side or on the right-hand side of the operator. The elements in expect must be char, num or raw, specifying the type of value the modifier expects, where raw means the value is not evaluated by the parser but returned as an uninterpreted string.

groupings

A character vector with new groupings; they must be in snake_case.

Examples

Run this code
curconfig <- lav_parse_options("testPKG",
    operators = c('%w%', '%q%'),
    modifiers = data.frame(mod = c("linksc", "linksn", "rechtsn"),
                           side = c("l", "l", "r"),
                           expect = c("char", "num", "raw")),
    groupings = c("color", "colour")
)
for (j in seq_along(curconfig)) {
    cat(names(curconfig)[j], ":\n")
    print(curconfig[[j]])
}
model <- '
     ind60 =~ x1 + x2 + x3
     dem60 =~ y1 + a*y2 + start(0.3)*b*y3 + upper(0.99)*c*y4
     dem65 =~ y5 + a*y6 + b*y7 + rechtsn(2 * pi / 3)*c*y8
     dem60 %w% aa *0.2*y4

    dem60 ~ ind60
    dem65 ~ ind60 + dem60
    linksc("klopt") * dem60 =~ aaa * y8
    linksn(sqrt(23.5)) * dem60 =~ bbb * y9
    efa("efatje") * dem65 =~ xyz * x3

    y1 ~~ y5
    y2 ~~ y4 + y6
    y3 ~~ y7
    y4 ~~ y8
    y6 ~~ y8
'
print(result <- lavParseModelString(model, TRUE, parser = "open"))
print(attributes(result))

model2 <- '
  color: green
    level: 1
        fw =~ y1 + y2 + y3
        fw ~ x1 + x2 + x3
    level: 2
        fb =~ y1 + y2 + y3
        fb ~ w1 + w2
  color: blue
    level: 1
        fw =~ y1 + y2 + y3
        fw ~ x1 + x2 + x3
    level: 2
        fb =~ y1 + y2 + y3
        fb ~ w1 + w2
'
print(result2 <- lavParseModelString(model2, TRUE, parser = "open"))
print(attributes(result2))

Run the code above in your browser using DataLab