R/id2name.R

Defines functions id2name

Documented in id2name

# convert a numeric to string

id2name <- function(dataframe){
	dataframe.new <- dataframe
	names.alt <- sub("id","",names(dataframe))
	for(i in grep("id",names(dataframe))){
		if(names.alt[i]=="version") next #no conversion for version ID
		repl <- getMetadata(names.alt[i], ID=dataframe[,i], EXACT=TRUE)

		if(!is.null(repl$Name)){
		     dataframe.new[,i] <- repl$Name
		}  else if (!is.null(repl$Description)){
		     dataframe.new[,i] <- repl$Description
		} else {
		     dataframe.new[,i] <- repl$ID
		}
	}
	if(NCOL(dataframe.new)!=NCOL(dataframe)){
		stop("lost columns in id2name")
	}
	names(dataframe.new) <- names.alt
	return(dataframe.new)
}

Try the RObsDat package in your browser

Any scripts or data that you put into this service are public.

RObsDat documentation built on May 31, 2017, 4:20 a.m.