Skip to content

Commit

Permalink
Simplify parsing of primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Oct 26, 2014
1 parent d7d97f7 commit b23f681
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions R/parse_arg_prim.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
parse_arg_prim <- function(x){

#in case of null we keep null
if(is.null(x)){
return(NULL);
}

#empty string
if(nchar(x) == 0){
if(!length(x) || !nchar(x)){
return(x);
}


#for json compatibility
if(x == "true" || x == "TRUE"){
return(TRUE);
}
Expand All @@ -19,15 +15,11 @@ parse_arg_prim <- function(x){
return(FALSE);
}

#check if it is a boolean, number or string
#check for boolean, number, string
myexpr <- parse(text=x);
if(identical(1L, length(myexpr))) {
obj <- myexpr[[1]];
if(is.character(obj) || is.logical(obj) || is.numeric(obj)) {
return(obj);
}
if(identical(1L, length(myexpr)) && is.atomic(myexpr[[1]])) {
return(myexpr[[1]])
} else {
return(x)
}

#default to no changes
return(x);
}

0 comments on commit b23f681

Please sign in to comment.