copySubstitute(Biobase)
copySubstitute()所属R语言包:Biobase
Copy Between Connections or Files with Configure-Like Name-Value Substitution
之间的连接或配置,如姓名,值替换的文件副本
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Copy files, directory trees or between connections and replace all occurences of a symbol by the corresponding value.
复制文件,目录树之间的连接和相应的值替换所有出现的象征。
用法----------Usage----------
copySubstitute(src, dest, symbolValues, symbolDelimiter="@", allowUnresolvedSymbols=FALSE, recursive = FALSE, removeExtension = "\\.in$")
参数----------Arguments----------
参数:src
Source, either a character vector with filenames and/or directory names, or a connection object.
源,无论是特征向量与文件名和/或目录名,或者一个连接对象。
参数:dest
Destination, either a character vector of length 1 with the name of an existing, writable directory, or a connection object. The class of the dest argument must match that of the src argument.
目的地,无论是现有的,可写目录的名称,或一个连接对象的长度1的特征向量。 dest参数的类必须符合的src论点。
参数:symbolValues
A named list of character strings.
一个名为字符串列表。
参数:symbolDelimiter
A character string of length one with a single character in it.
在单个字符长度的字符串。
参数:allowUnresolvedSymbols
Logical. If FALSE, then the function will execute stop if it comes across symbols that are not defined in symbolValues.
逻辑。如果FALSE,那么该函数将执行stop如果它跨symbolValues不定义的符号来。
参数:recursive
Logical. If TRUE, the function works recursively down a directory tree (see details).
逻辑。如果TRUE,功能工程递归下降的目录树(见详情)。
参数:removeExtension
Character. Matches to this regular expression are removed from filenames and directory names.
字符。这个正则表达式匹配从文件名和目录名。
Details
详情----------Details----------
Symbol substitution: this is best explained with an example. If the list symbolValues contains an element with name FOO and value bar, and symbolDelimiter is @, then any occurrence of @FOO@ is replaced by bar. This applies both the text contents of the files in src as well as to the filenames. See examples.
符号替换:这是最好用一个例子来解释。如果列表symbolValues包含元素名称FOO和价值bar,symbolDelimiter@,则@FOO@发生任何取代<X >这适用于bar以及文件名的文件的文本内容。看到的例子。
If recursive is FALSE, both src and dest must be connection or a filenames. The text in src is read through the function readLines, symbols are replaced by their values, and the result is written to dest through the function writeLines.
如果recursive是FALSE都src和dest必须连接或文件名。在src文本读通过功能readLines,符号取代他们的价值观,通过功能destwriteLines结果被写入。
If recursive is TRUE, copySubstitute works recursively down a directory tree (see details and example). src must be a character vector with multiple filenames or directory names, dest a directory name.
如果recursive是TRUE,copySubstitute下一个目录树的递归(见细节和例子)。 src必须与多个文件名或目录名的字符向量,dest一个目录名。
One use of this function is in createPackage for the automatic generation of packages from a template package directory.
这个函数的用途之一是在createPackage包从一个模板包目录自动生成。
值----------Value----------
None. The function is called for its side effect.
没有。该功能被称为其副作用。
作者(S)----------Author(s)----------
Wolfgang Huber <a href="http://www.dkfz.de/mga/whuber">http://www.dkfz.de/mga/whuber</a>
举例----------Examples----------
## create an example file[#创建一个示例文件。]
infile = tempfile()
outfile = tempfile()
writeLines(text=c("We will perform in @WHAT@:",
"So, thanks to @WHOM@ at once and to each one,",
"Whom we invite to see us crown'd at @WHERE@."),
con = infile)
## create the symbol table[#创建符号表]
z = list(WHAT="measure, time and place", WHOM="all", WHERE="Scone")
## run copySubstitute[#运行copySubstitute]
copySubstitute(infile, outfile, z)
## display the results[#显示的结果。]
readLines(outfile)
##--------------------------------------------------------------[#------------------------------------------------- -------------]
## This is a slightly more complicated example that demonstrates[#这是一个稍微复杂的例子,它说明]
## how copySubstitute works on nested directories[#如何copySubstitute上嵌套目录]
##--------------------------------------------------------------[#------------------------------------------------- -------------]
d = tempdir()
my.dir.create = function(x) {dir.create(x); return(x)}
unlink(file.path(d, "src"), recursive=TRUE)
unlink(file.path(d, "dest"), recursive=TRUE)
## create some directories and files:[#创建一些目录和文件:]
src = my.dir.create(file.path(d, "src"))
dest = file.path(d, "dest")
d1 = my.dir.create(file.path(src, "dir1.in"))
d2 = my.dir.create(file.path(src, "dir2@FOO@.in"))
d3 = my.dir.create(file.path(d2, "dir3"))
d4 = my.dir.create(file.path(d3, "dir4"))
d5 = my.dir.create(file.path(d4, "dir5@BAR@"))
writeLines(c("File1:", "FOO: @FOO@"), file.path(d1, "file1.txt.in"))
writeLines(c("File2:", "BAR: @BAR@"), file.path(d2, "file2.txt.in"))
writeLines(c("File3:", "SUN: @SUN@"), file.path(d3, "file3.txt.in"))
writeLines(c("File4:", "MOON: @MOON@"), file.path(d4, "@SUN@.txt"))
## call copySubstitute[#调用copySubstitute]
copySubstitute(src, dest, recursive=TRUE,
symbolValues = list(FOO="thefoo", BAR="thebar",
SUN="thesun", MOON="themoon"))
## view the result[#查看结果]
listsrc = dir(src, full.names=TRUE, recursive=TRUE)
listdest = dir(dest, full.names=TRUE, recursive=TRUE)
listsrc
listdest
cat(unlist(lapply(listsrc, readLines)), sep="\n")
cat(unlist(lapply(listdest, readLines)), sep="\n")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|