File: greplVarType.R

package info (click to toggle)
r-cran-semplot 1.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 464 kB
  • sloc: makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# grepl on varnames with special keywords:
# - MAN
# - LAT
# - ENDO
# - EXO
# - INT

matchVar <- function(x, Vars, manIntsExo, manIntsEndo, latIntsExo, latIntsEndo)
{
  
  n <- nrow(Vars) + nrow(manIntsEndo)  + nrow(manIntsExo)  + nrow(latIntsEndo)  + nrow(latIntsExo) 
  
  Man <- c(Vars$manifest, rep(FALSE,n-nrow(Vars)))
  Man[c(manIntsEndo[,1],manIntsExo[,1])] <- TRUE
  
  Exo <- c(Vars$exogenous, rep(FALSE,n-nrow(Vars)))
  Exo[c(manIntsExo[,1],latIntsExo[,1])] <- TRUE
  
  isInt <- c(rep(FALSE,nrow(Vars)), rep(TRUE, n-nrow(Vars)))
  
  # match:
  matchRes <- match(x,Vars$name)
  matchRes <- matchRes[!is.na(matchRes)]
  
  # keywords:
  select <- rep(grepl("(EXO)|(ENDO)|(MAN)|(LAT)|(INT)|(VAR)",x),n)
  
  if (any(select))
  {
    
    if (grepl("(ENDO)|(EXO)",x))
    {      
      # First node first / endo:
      select <- select & ((grepl("ENDO",x) & !Exo) | 
                            (grepl("EXO",x) & Exo )
      )
    }
    
    if (grepl("(LAT)|(MAN)",x))
    {
      
      # Any node man / latent
      select <- select & ((grepl("LAT",x) & !Man) | 
                            (grepl("MAN",x) & Man )
      )
    }
    
    if (grepl("(INT)|(VAR)",x))
    {
      
      # Any node man / latent
      select <- select & ((grepl("VAR",x) & !isInt) | 
                            (grepl("INT",x) & isInt )
      )
    }
     
  }
  
  return(c(matchRes,which(select)))
}