R/DM.studentTyped.R

Defines functions DM.studentTyped

Documented in DM.studentTyped

DM.studentTyped <- function(string, user.code=DM.user.code){
  # Remove white spaces, ";" and "\n" from string & user.code
  user.code <- gsub( "[[:space:]]|;|\n","",user.code )
  string <- gsub( "[[:space:]]|;|\n","",string )
  
  # Student can choose to assign by "<-" or "=", this shouldn't matter
  user.code <- gsub( "<-","=",user.code )
  string <- gsub( "<-","=",string )
  # Student can choose to TRUE/T and FALSE/F
  user.code <- gsub( "FALSE","F", user.code )
  string    <- gsub( "FALSE","F", string )  
  user.code <- gsub( "TRUE", "T", user.code )  
  string    <- gsub( "TRUE", "T", string )
  
  # Find reg ex and return result:  
  where.is.regex <- gregexpr(pattern=string, text=user.code,fixed=TRUE)
  if( any(where.is.regex[[1]] == (-1)) ){ return(FALSE) } # No match for the reg ex 
  n <- length(where.is.regex[[1]])
  return(n)
}
jonathancornelissen/DM documentation built on May 19, 2019, 7:27 p.m.