Read Relational Data Values
read_adjacency_list.RdRead relational data from a file in adjacency list format and parse it into a
LinkMap (or a LinkMap-shaped data.frame). Relies on base::scan and
utils::count.fields under the hood.
Usage
read_adjacency_list(
file,
sep = "\t",
quote = "'\"",
col.names = c("id.x", "id.y"),
as.df = FALSE,
...
)Arguments
- file
the name of a file to read data values from. If the specified file is
"", then input is taken from the keyboard (or whateverstdin()reads if input is redirected or R is embedded). (In this case input can be terminated by a blank line or an signal, Ctrl-D on Unix and Ctrl-Z on Windows.)Otherwise, the file name is interpreted relative to the current working directory (given by
getwd()), unless it specifies an absolute path. Tilde-expansion is performed where supported. When running R from a script,file = "stdin"can be used to refer to the process'sstdinfile stream.This can be a compressed file (see
file).Alternatively,
filecan be aconnection, which will be opened if necessary, and if so closed at the end of the function call. Whatever mode the connection is opened in, any of , or will be accepted as the marker for a line and so will matchsep = "\n".filecan also be a complete URL. (For the supported URL schemes, see the ‘URLs’ section of the help forurl.)To read a data file not in the current encoding (for example a Latin-1 file in a UTF-8 locale or conversely) use a
fileconnection setting itsencodingargument (orscan'sfileEncodingargument).- sep
the field separator character. Values on each line of the file are separated by this character. (Default:
"\t")- quote
the set of quoting characters as a single character string or
NULL. In a multibyte locale the quoting characters must be ASCII (single-byte).- col.names
Character vectorof length 2, specifying the colnames of the output. (Default:c("id.x", "id.y"))- as.df
BooleanWhether to return an unmodifieddata.frameor aLinkMap(Default).- ...
Additional arguments, passed to
scan.
Value
A LinkMap, or if( as.df ), a two-column data.frame formatted
like an edge list, appropriate input for LinkMap().
Details
Note that the other common representation of relational data, a two-column
table, known as an edge list, can be read in using regular approaches
(e.g., ?base::read.table).