R/parse_arg_prim.R

Defines functions parse_arg_prim

#very simple function that recognizes numbers and booleans
parse_arg_prim <- function(x){

  #in case of null we keep null
  if(!length(x) || !nchar(x)){
    return(x);
  }

  #for json compatibility
  if(x == "true" || x == "TRUE"){
    return(TRUE);
  }

  if(x == "false" || x == "FALSE"){
    return(FALSE);
  }

  #check for boolean, number, string
  myexpr <- parse_utf8(x)
  if(identical(1L, length(myexpr)) && is.atomic(myexpr[[1]])) {
    return(myexpr[[1]])
  } else {
    return(x)
  }
}
jeroen/opencpu documentation built on Aug. 21, 2023, 12:09 p.m.