These functions are for working with source files.
Usage
srcfile(filename, encoding = getOption("encoding"), Enc = "unknown")
srcfilecopy(filename, lines, timestamp = Sys.time(), isFile = FALSE)
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, to = x, ...)
.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.
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.
isFile
Is this srcfilecopy known to come from a file system file?
srcfile
A srcfile object.
first, last, line
Line numbers.
lloc
A vector of four, six or eight values giving a source location; see
‘Details’.
x, object, con
An object of the appropriate class.
useSource
Whether to read the srcfile to obtain the
text of a srcref.
to
An optional second srcref object to mark the end
of the character range.
...
Additional arguments to the methods; these will be ignored.
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.
The srcfilecopy function produces an object of the descendant
class srcfilecopy, which saves the source lines in a character
vector. It copies the value of the isFile argument, to help
debuggers identify whether this text comes from a real file in the
file system.
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.
The getSrcLines function reads the specified lines from
srcfile.
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:
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.
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.
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. If the to argument is given,
it should be a second srcref that follows the first, in the
same file; they will be treated as one reference to the whole
range. 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.
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.
.isOpen is intended for internal use: it checks whether the
connection associated with a srcfile object is open.
Value
srcfile returns a srcfile object.
srcfilecopy returns a srcfilecopy object.
getSrcLines returns a character vector of source code lines.
srcref returns a srcref object.
Author(s)
Duncan Murdoch
See Also
getSrcFilename for extracting information from a source reference.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(base)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/base/srcfile.Rd_%03d_medium.png", width=480, height=480)
> ### Name: srcfile
> ### Title: References to source files
> ### Aliases: srcfile srcfilecopy getSrcLines srcref srcfile-class
> ### srcfilecopy-class srcref-class print.srcfile summary.srcfile
> ### open.srcfile open.srcfilecopy close.srcfile print.srcref
> ### summary.srcref as.character.srcref .isOpen srcfilealias-class
> ### srcfilealias open.srcfilealias close.srcfilealias
> ### Keywords: debugging utilities
>
> ### ** Examples
> ## No test:
> # has timestamp
> src <- srcfile(system.file("DESCRIPTION", package = "base"))
> summary(src)
/home/ddbj/local/lib64/R/library/base/DESCRIPTION
Timestamp: 2016-06-29 14:24:47 JST
Encoding: "native.enc"
> getSrcLines(src, 1, 4)
[1] "Package: base" "Version: 3.3.1"
[3] "Priority: base" "Title: The R Base Package"
> ref <- srcref(src, c(1, 1, 2, 1000))
> ref
Package: base
Version: 3.3.1
> print(ref, useSource = FALSE)
<srcref: file "/home/ddbj/local/lib64/R/library/base/DESCRIPTION" chars 1:1 to 2:1000>
> ## End(No test)
>
>
>
>
> dev.off()
null device
1
>