11.1 On vectors
- Read a file as a vector with the scan function
By default, scans “double” (numeric) elements: it fails if the input contains characters.
If non-numeric, you need to specify the type of data contained in the file:
# specify the type of data to scan
scan(file="file.txt",
what="character")
scan(file="~/file.txt",
what="character")
Regarding paths of files:
If the file is not in the current directory, you can provide a full or relative path. For example, if located in the home directory, read it as:
- Write the content of a vector in a file:
# create a vector
mygenes <- c("SMAD4", "DKK1", "ASXL3", "ERG", "CKLF", "TIAM1", "VHL", "BTD", "EMP1", "MALL", "PAX3")
# write in a file
write(x=mygenes,
file="gene_list.txt")
Regarding paths of files:
When you write a file, you can also specify a full or relative path: