1 | read.spectrum.file(fileToRead, encoding = "UTF-8", cols = 2, pattern.blank = "[[:blank:],;]", pattern.num = "([-]?[0-9]+[.]?[0-9]*[Ee]*[+-]*[0-9]{0,5})")
|
fileToRead |
|
encoding |
|
cols |
|
pattern.blank |
|
pattern.num |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (fileToRead, encoding = "UTF-8", cols = 2, pattern.blank = "[[:blank:],;]",
pattern.num = "([-]?[0-9]+[.]?[0-9]*[Ee]*[+-]*[0-9]{0,5})")
{
con <- file(fileToRead, "r", blocking = FALSE, encoding = encoding)
strdata <- readLines(con)
close(con)
pattern.row <- paste(sprintf("^%s*", pattern.blank), paste(rep(pattern.num,
cols), sep = "", collapse = sprintf("%s+", pattern.blank)),
sprintf("%s*$", pattern.blank), sep = "", collapse = "")
is.number.row <- regexpr(pattern.row, strdata) == T
strdata.onlydata <- strdata[is.number.row]
data.length <- length(strdata.onlydata)
outdata <- matrix(nrow = data.length, ncol = cols)
for (j in 1:cols) {
outdata[, j] <- as.numeric(gsub(pattern.row, sprintf("\%1.0f",
j), strdata.onlydata, ))
}
return(list(outdata = outdata, filename = fileToRead, origin.file.content = strdata,
row.not.used = which(is.number.row == F), encoding = encoding,
grep.pattern = pattern.row, cols = cols, data.length = data.length))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.