#' Check if the argument is a valid variable name
#'
#' @param A Input string vector or list
#'
#' @details
#' varname is a string starting with \code{[:alpha:]} or \code{.}
#'  and having no \code{[:punct:]} except \code{.} or \code{_} .
#'
#' @return
#' A logical vector
#'
#' @examples
#' is.varname( c("and2","age_1_x","a.1","a_1.","1.","_a",".a") )
#'
#' @export
#'

is.varname <- function( A ){
 # checking if the input is a valid variable name
 # Shin-ichi Mayekawa
 # 121228
 # _ and . added: 20150803
 # new method w/o trim: 20220927dnc
 #
 #
 # varname is a string starting with [:alpha:] or .
 #                                     and having no [:punct:] except _.
 #

 if( length(A) == 1 ){
  # single input
  cond=length( grep("[ ]*^[a-zA-Z\\.][a-zA-Z_\\.0-9]*[ ]*$",A) ) > 0
  return( cond )
 }
 else{
  # recursive call for vector input:  cannot use Recall here in lapply!!
  return( unlist(lapply(A, is.varname)) )
 }

} # end of is.varname


