#' Keep or Drop the variables in the data frame
#' 
#' @param df The data frame whose variables are to be kept/dropped.
#' @param keep A vector consisting of the names of the variables to keep\cr
#' or sas-like abbreviated list of variables to keep as a string.
#' @param drop A vector consisting of the names of the variables to drop\cr
#' or sas-like abbreviated list of variables to drop as a string.
#'
#' @examples
#' df <- as.data.frame(demomat(5,7))
#' names(df) <- c("x1","x2","x3","a","s","m","i")
#'
#' keepdrop( df, keep=c("x1", "a", "x3") )
#' keepdrop( df, keep="x1 a x3" )
#' keepdrop( df, keep="x1-x3 m" )
#' keepdrop( df, keep="x1--m" )
#'
#' keepdrop( df, drop=c("x1", "a", "x3") )
#' keepdrop( df, drop="x1 a x3" )
#' keepdrop( df, drop="x1-x3 m" )
#' keepdrop( df, drop="x1--m" )
#'
#' @details
#' This functin first expands the abbreviated variable list by varlst function.
#' \cr
#' Then, it creats a data frame with the variables in the keep list. \cr
#' Finally, it drops those variable in the drop list.
#'
#'
#' @return
#' A data frame
#'
#' @export
#'

keepdrop <- function( df, keep=NULL, drop=NULL ){
 # keep or drop variables from a data frame
 # Shin-ichi Mayekawa
 # 20170912dnc
 # roxgen comment: 20170922
 #
 if( !is.null(keep)){
  keep=varlist( keep, varlistf=names(df) )
  df=df[,keep, drop=0]
 }
 if( !is.null(drop)){
  drop=varlist( drop, varlistf=names(df) )
  df=df[,!(names(df) %in% drop), drop=0]
 }
 return( df )
} # end of keepdrop


