Important libraries
connections {base}
Read in
# Read in table and fill empty values
d = read.table(fName, sep ='\t', fill = TRUE, stringsAsFactors = FALSE)
# Read in table with different seperators
d = read.delim(fName, fill = TRUE, stringsAsFactors = FALSE)
d = read.csv(fName, FALSE)
# Read json files
library(jsonlite)
a <-fromJSON(fName)
# Read excel file
library(xlsx)
wb <- loadWorkbook(file = WF_TEMPLATE_FILENAME)
# scan is more flexible but needs to know at forehand the expected data structure
d = scan(fName, what = list(character(),double(0),double()), skip =1)
# Fast read
d = fread(fName, sep ='\t', stringsAsFactors = FALSE)
# process script file
source('~/Ranalyses/PaperOneFinal/getData.R')
# Read stdout from command line pipe
readLines(pipe("ls -1")) #linux
readLines(pipe("dir ")) #windows
cmd = "ls -1"
system(cmd, intern = T)
# Read string from file
readChar(TEMPLATE_NAME, file.info(TEMPLATE_NAME)$size)
# read large files and concatenate efficiently
listDT = list()
for (i in 1 : nrow(files)){
f = files[i,]
dt = fread(f$fileName)
df$sampleId = f$sampleId
listDT[[i]] = dt
}
dtAll = rbindlist(listDT)
Out
# write to standard output
write.table(df, "out.txt", row.names = F, quote = F)
# write to standard output
write("My message", stdout())
# write to excel sheet
wb = createWorkbook()
sheet = createSheet(wb, sheetName = "MySheet")
addDataFrame(df, sheet, startRow = 1, startColumn = 1, row.names = FALSE)
saveWorkbook(wb, outputFile)
write(toJSON(df), stdout())
# redirect output to file
sink('data/sink.txt', append = F)
print("hello")
sink()
print("hello")
# write to standard output and quit
stop("My crash message")
#Write updating row to stdout()
cat('\rProcessed', row, 'out of',nrow(sub), 'rows. Added',nBases, 'base pairs to', newFile)
flush.console()
# quit with error status
q(status = 1)
# get files not matching a certain pattern
notOnly = !grepl('myPattern', list.files(paste0(outputFolder, '/', sampleId), pattern='withFilters'))
list.files(paste0(outputFolder, '/', sampleId),pattern='withFilters')[notOnly]