"get.metadata" <- function(meta,useHead=NULL,filters=NULL,include=NULL,exclude=NULL) { if(!is.null(useHead) && (!is.character(useHead) || (length(useHead)==0))) stop("Header must be either NULL or of type non-empty character") if(!is.null(filters) && (!is.list(filters) || (length(filters)==0) || !is.character(unlist(filters)) || is.null(names(filters)))) stop("Filters must be either NULL or of type non-empty tagged character list") if(!is.null(include) && (!is.character(include) || (length(include)==0))) stop("Include must be either NULL or of type non-empty character") if(!is.null(exclude) && (!is.character(exclude) || (length(exclude)==0))) stop("Exclude must be either NULL or of type non-empty character") meta <- unlist(meta) if(is.null(meta) || is.na(meta)) return(as.character(NA)) mInds <- 1:length(meta) mIndsMatch <- rep(TRUE,length(mInds)) if(!is.null(useHead)) { mInds <- mInds[grep(useHead,names(meta))] mIndsMatch <- mIndsMatch[mInds] if(!is.null(filters)) { for(i in 1:length(filters)) { fInds <- grep(names(filters[i]),names(meta)) fIndsMatch <- (meta[fInds]%in%unlist(filters[i])) mIndsMatch <- mIndsMatch & fIndsMatch } } } meta <- as.list(as.character(meta[mInds[mIndsMatch]])) meta <- lapply(meta,remove.meta.chars) meta <- unique(unlist(meta)) if(is.null(meta)) return(as.character(NA)) if(!is.null(include)) meta <- meta[meta %in% include] if(!is.null(exclude)) meta <- meta[!(meta %in% exclude)] if(length(meta)==0) return(as.character(NA)) return(meta) }