asked 95.5k views
4 votes
The code snippet con <- file("", "r") data <- (con) close(con) is the same as:

A) con <- file("", "r") data <- readLines(con) close(con)
B) con <- file("", "r") data <- readRDS(con) close(con)
C) con <- file("", "r") data <- readBin(con, what = "raw", n = file.info(con)$size) close(con)
D) con <- file("", "r") data <- readRDS(file = con) close(con)
Which option is correct?

asked
User Jdscolam
by
8.5k points

1 Answer

5 votes

Final answer:

The correct option is C) con <- file("", "r") data <- readBin(con, what = "raw", n = file.info(con)$size) close(con).

Step-by-step explanation:

The correct option is C) con <- file("", "r") data <- readBin(con, what = "raw", n = file.info(con)$size) close(con).

In this code snippet, the file() function is used to open a file for reading, with the argument "r" indicating that the file should be opened in read mode.

The readBin() function is then used to read the data from the file into the variable data. The arguments to readBin() specify that the data should be read as raw bytes, and that the number of bytes to read should be equal to the size of the file.

answered
User Anatoli Klamer
by
9.1k points