[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  scan: Read Data Values

##  Description

Read data into a vector or list from the console or file.

##  Usage

    
    
    scan(file = "", what = double(), nmax = -1, n = -1, sep = "",
         quote = if(identical(sep, "\n")) "" else "'\"", dec = ".",
         skip = 0, nlines = 0, na.strings = "NA",
         flush = FALSE, fill = FALSE, strip.white = FALSE,
         quiet = FALSE, blank.lines.skip = TRUE, multi.line = TRUE,
         comment.char = "", allowEscapes = FALSE,
         fileEncoding = "", encoding = "unknown", text, skipNul = 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 whatever ` [ stdin
](/link/stdin?package=base&version=3.6.2) () ` reads if input is redirected or
R  is embedded). (In this case input can be terminated by a blank line or an
EOF 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 ](/link/getwd?package=base&version=3.6.2) () `
), 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's ` stdin ` file stream.

This can be a compressed file (see ` [ file
](/link/file?package=base&version=3.6.2) ` ).

Alternatively, ` file ` can be a ` [ connection
](/link/connection?package=base&version=3.6.2) ` , 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 LF, CRLF or CR will be accepted as the EOL
marker for a line and so will match ` sep = "\n" ` .

` file ` can also be a complete URL. (For the supported URL schemes, see the
‘URLs’ section of the help for ` [ url ](/link/url?package=base&version=3.6.2)
` .)

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 ` [ file
](/link/file?package=base&version=3.6.2) ` connection setting its ` encoding `
argument (or ` scan ` 's ` fileEncoding ` argument).

what

the [ type ](/link/type?package=base&version=3.6.2) of ` what ` gives the type
of data to be read. (Here ‘type’ is used in the sense of ` [ typeof
](/link/typeof?package=base&version=3.6.2) ` .) The supported types are `
logical ` , ` integer ` , ` numeric ` , ` complex ` , ` character ` , ` raw `
and ` [ list ](/link/list?package=base&version=3.6.2) ` . If ` what ` is a
list, it is assumed that the lines of the data file are records each
containing ` length(what) ` items (‘fields’) and the list components should
have elements which are one of the first six ( [ atomic
](/link/atomic?package=base&version=3.6.2) ) types listed or ` NULL ` , see
section ‘Details’ below.

nmax

the maximum number of data values to be read, or if ` what ` is a list, the
maximum number of records to be read. If omitted or not positive or an invalid
value for an integer (and ` nlines ` is not set to a positive value), ` scan `
will read to the end of ` file ` .

n

integer: the maximum number of data values to be read, defaulting to no limit.
Invalid values will be ignored.

sep

by default, scan expects to read ‘white-space’ delimited input fields.
Alternatively, ` sep ` can be used to specify a character which delimits
fields. A field is always delimited by an end-of-line marker unless it is
quoted.

If specified this should be the empty character string (the default) or ` NULL
` or a character string containing just one single-byte character.

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

dec

decimal point character. This should