ID EN
Miscellaneous

srcfile

R Base 3.6.2

These functions are for working with source files and more generally with “source references” ("srcref"), i.e., references to source code. The resulting data is used for printing and source level debugging, and is typically available in interactive R sessions, namely when options(keep.source = TRUE).

Syntax

R
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 srcfile
print(x, …)
# S3 method for srcfile
summary(object, …)
# S3 method for srcfile
open(con, line, …)
# S3 method for srcfile
close(con, …)
# S3 method for srcref
print(x, useSource = TRUE, …)
# S3 method for srcref
summary(object, useSource = FALSE, …)
# S3 method for srcref
as.character(x, useSource = TRUE, to = x, …)
.isOpen(srcfile)

Arguments

Parameter Description
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.

Return 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.

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 t

Examples

Example
R
# NOT RUN {
 # has timestamp
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)
# }

See Also

getSrcFilename for extracting information from a source reference or removeSource to remove it from a (non-primitive) function (aka ‘closure’).