srcfile(base)
srcfile()所属R语言包:base
References to source files
参考源文件
译者:生物统计家园网 机器人LoveR
描述----------Description----------
These functions are for working with source files.
这些功能都与源文件的工作。
用法----------Usage----------
srcfile(filename, encoding = getOption("encoding"), Enc = "unknown")
srcfilecopy(filename, lines, timestamp = Sys.time())
srcfilealias(filename, srcfile)
getSrcLines(srcfile, first, last)
srcref(srcfile, lloc)
## S3 method for class 'srcfile'
print(x, ...)
## S3 method for class 'srcfile'
summary(object, ...)
## S3 method for class 'srcfile'
open(con, line, ...)
## S3 method for class 'srcfile'
close(con, ...)
## S3 method for class 'srcref'
print(x, useSource = TRUE, ...)
## S3 method for class 'srcref'
summary(object, useSource = FALSE, ...)
## S3 method for class 'srcref'
as.character(x, useSource = TRUE, ...)
.isOpen(srcfile)
参数----------Arguments----------
参数:filename
The name of a file.
文件名。
参数:encoding
The character encoding to assume for the file.
承担文件的字符编码。
参数:Enc
The encoding with which to make strings: see the encoding argument of parse.
编码使字符串:encodingparse参数。
参数:lines
A character vector of source lines. Other R objects will be coerced to character.
源代码行的一个特征向量。其他研究对象,将被强制性质。
参数:timestamp
The timestamp to use on a copy of a file.
使用时间戳文件的副本。
参数:srcfile
A srcfile object.
一个srcfile对象。
参数:first, last, line
Line numbers.
行号。
参数:lloc
A vector of four, six or eight values giving a source location; see "Details".
四个向量,6个或8个价值,给人一种源位置;看到“详细资料”。
参数:x, object, con
An object of the appropriate class.
一个适当的类的对象。
参数:useSource
Whether to read the srcfile to obtain the text of a srcref.
是否读取srcfile获得一个srcref文本。
参数:...
Additional arguments to the methods; these will be ignored.
额外的参数的方法,这些都将被忽略。
Details
详情----------Details----------
These functions and classes handle source code references.
这些函数和类处理源代码引用。
The srcfile function produces an object of class srcfile, which contains the name and directory of a source code file, along with its timestamp, for use in source level debugging (not yet implemented) and source echoing. The encoding of the file is saved; see file for a discussion of encodings, and iconvlist for a list of allowable encodings on your platform.
srcfile函数产生一个类的对象srcfile,其中包含一个源代码文件的名称和目录,连同其时间戳,用于在源代码级调试(尚未实施)和源呼应。保存该文件的编码;看到file编码的讨论,和iconvlist为你的平台上允许的编码列表。
The srcfilecopy function produces an object of the descendant class srcfilecopy, which saves the source lines in a character vector.
srcfilecopy函数生成一个子类srcfilecopy,从而节省了一个字符向量中的源代码行的对象。
The srcfilealias function produces an object of the descendant class srcfilealias, which gives an alternate name to another srcfile. This is produced by the parser when a #line directive is used.
srcfilealias函数产生的子类srcfilealias,给出了一个备用名称到另一个SRCFILE的对象。这是由#line指令时使用的解析器。
The getSrcLines function reads the specified lines from srcfile.
从getSrcLinessrcfile函数读取指定的行。
The srcref function produces an object of class srcref, which describes a range of characters in a srcfile. The lloc value gives the following values: c (first_line, first_byte, last_line, last_byte, first_column, last_column, first_parsed, last_parsed). Bytes (elements 2, 4) and columns (elements 5, 6) may be different due to multibyte characters. If only four values are given, the columns and bytes are assumed to match. Lines (elements 1, 3) and parsed lines ( elements 7, 8) may differ if a #line directive is used in code: the former will respect the directive, the latter will just count lines. If only 4 or 6 elements are given, the parsed lines will be assumed to match the lines.
srcref函数产生一个类的对象:srcref,它描述一个字符 srcfile的范围。 lloc价值为以下值:c (first_line, first_byte, last_line, last_byte, first_column, last_column, first_parsed, last_parsed)。字节(元素2,4)和列(元素5,6),可能是由于多字节字符的不同。如果只有四个值,假定列和字节相匹配。线(元素1,3)和解析线(元素7,8),可能会有所不同,如果#line指令在代码中使用:前者将尊重指令,后者将只计算行。如果只有4个或6个元素,分析线将假定相匹配的行。
Methods are defined for print, summary, open, and close for classes srcfile and srcfilecopy. The open method opens its internal file connection at a particular line; if it was already open, it will be repositioned to that line.
方法被定义为print,summary,open,close类srcfile和srcfilecopy。 open方法打开其内部file在一个特定的行连接,如果是已经打开,它会被重新定位到该行。
Methods are defined for print, summary and as.character for class srcref. The as.character method will read the associated source file to obtain the text corresponding to the reference. The exact behaviour depends on the class of the source file. If the source file inherits from class "srcfilecopy", the lines are taken from the saved copy using the "parsed" line counts. If not, an attempt is made to read the file, and the original line numbers of the srcref record (i.e. elements 1 and 3) are used. If an error occurs (e.g. the file no longer exists), text like <srcref: "file" chars 1:1 to 2:10> will be returned instead, indicating the line:column ranges of the first and last character. The summary method defaults to this type of display.
方法被定义为print,summary和as.character类srcref。 as.character方法将读取相关的源文件,以获得相应的参考文本。确切行为取决于源文件的类。如果源文件从类继承"srcfilecopy",该行采取使用“解析”线数从保存副本。如果不是,企图读取该文件,和的srcref纪录(即元素1和3)的原始行号使用。如果发生错误(例如文件不再存在),像将<srcref: "file" chars 1:1 to 2:10>返回,表明line:column的第一个和最后一个字符范围的文本。 summary方法默认这种类型显示。
Lists of srcref objects may be attached to expressions as the "srcref" attribute. (The list of srcref objects should be the same length as the expression.) By default, expressions are printed by print.default using the associated srcref. To see deparsed code instead, call print with argument useSource = FALSE. If a srcref object is printed with useSource = FALSE, the <srcref: ...> record will be printed.
名单srcref对象可以附加"srcref"属性表达式。 (名单srcref对象应该是为表达相同的长度。)默认情况下,表达式印print.default使用相关的srcref。要看到deparsed的代码,而是叫print参数useSource = FALSE。如果印srcref,useSource = FALSE对象<srcref: ...>记录将被打印。
.isOpen is intended for internal use: it checks whether the connection associated with a srcfile object is open.
.isOpen供内部使用,它会检查srcfile对象相关联的连接是否是开放的。
值----------Value----------
srcfile returns a srcfile object.
srcfile返回srcfile对象。
srcfilecopy returns a srcfilecopy object.
srcfilecopy返回srcfilecopy对象。
getSrcLines returns a character vector of source code lines.
getSrcLines返回一个行源代码的特征向量。
srcref returns a srcref object.
srcref返回srcref对象。
作者(S)----------Author(s)----------
Duncan Murdoch
举例----------Examples----------
src <- srcfile(system.file("DESCRIPTION", package = "base"))
summary(src)
getSrcLines(src, 1, 4)
ref <- srcref(src, c(1, 1, 2, 1000))
ref
print(ref, useSource = FALSE)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|