force.vec: returns a vector if 'unknown.data' can in anyway relate to...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/reader.R

Description

if the name of a file with a vector or vector, then reads the file, if a matrix or dataframe, then preferentially return rownames, otherwise return first column - designed to search for IDs. Using this within functions allows flexibility in the specification of a datasource for vectors

Usage

1
force.vec(unknown.data, most.unique = TRUE, dir = NULL, warn = FALSE)

Arguments

unknown.data

something that is or can refer to a 2d dataset

most.unique

if TRUE, select most unique column if a unknown.data is a matrix, else select the first column

dir

if unknown.data is a file name, specifies directory(s) to look for the file

warn

whether to display a warning if unknown.data is a matrix

Value

returns a vector regardless of the original object type

Author(s)

Nicholas Cooper nick.cooper@cimr.cam.ac.uk

See Also

force.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# create a matrix, binary file, and simple vector
my.ids <- paste("ID",1:4,sep="")
my.dat <- sample(2,4,replace=TRUE)
test.files <- c("temp.rda")
mymat <- cbind(my.ids,my.dat)
save(mymat,file=test.files[1])
test.vecs <- list(myvec = my.ids,
 myrda = test.files[1],mymat=mymat)
# show dimensions of each test object
sapply(test.vecs,function(x) {  if(is.null(dim(x))){ length(x)} else {dim(x)}})
# run the function on each, reporting specs of the object returned
for (cc in 1:3) {
  the.vec <- force.vec(test.vecs[[cc]])
  cat(names(test.vecs)[cc],": length() => ",
      length(the.vec),"; is() => ",is(the.vec)[1],"\n",sep="")
}
unlink(test.files)

reader documentation built on May 2, 2019, 9:27 a.m.