R Programming Questions and Answers – Connection Interfaces

«
»

This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Connection Interfaces”.

1. Individual R objects can be saved to a file using the _____ function.
a) save
b) put
c) save_image
d) get
View Answer

Answer: a
Explanation: The key functions for converting R objects into a binary format are save(), save.image(), and serialize().

2. Point out the correct statement?
a) The complement to the textual format is the binary format
b) If you have a lot of objects that you want to save to a file, you can save all objects in your workspace using the save.image() function
c) The serialize() function is used to convert individual R objects into a binary format that can be communicated across an arbitrary connection
d) All of the mentioned
View Answer

Answer: d
Explanation: It’s better to stick with a binary format for efficiency and accuracy.

advertisement

3. Which of the following R statement will save the output to the file for following R code?

> a <- data.frame(x = rnorm(100), y = runif(100))
> b <- c(3, 4.4, 1 / 3)

a) save(a, b, file = “mydata.rda”)
b) save_image(a, b, file = “mydata.rda”)
c) keep(a, b, file = “mydata.rda”)
d) keep_image(a, b, file = “mydata.rda”)
View Answer

Answer: a
Explanation: You can save all objects in your workspace using the save.image() function.

4. Which of the following statement will load the objects to the file named “mydata.RData”?
a) save(“mydata.RData”)
b) load(“mydata.RData”)
c) loadAll(“mydata.RData”)
d) put(“mydata.RData”)
View Answer

Answer: b
Explanation: .rda and .RData are fairly common extensions and you may want to use them because they are recognized by other software.

advertisement

5. Point out the wrong statement?
a) When you call unserialize() on an R object, the output will be a raw vector coded in hexadecimal format
b) serialize() function is the only way to perfectly represent an R object in an exportable format
c) .rda extension is used when save() function is incorporated
d) The complement to the textual format is the binary format
View Answer

Answer: a
Explanation: Output may get sent to a file, but it could get sent over a network or other connection.

6. ________ opens a connection to a file compressed with gzip.
a) url
b) gzfile
c) bzfile
d) file
View Answer

Answer: b
Explanation: “file” opens a connection to a file.

7. Connections to text files can be created with the ________ function.
a) url
b) gzfile
c) bzfile
d) file
View Answer

Answer: d
Explanation: The file() function has a number of arguments that are common to many other connection functions.

8. Which of the following R code creates a connection to ‘foo.txt’?
a) con <- file(“foo.txt”)
b) open(con, “r”)
c) opencon(con, “r”)
d) ocon(con, “r”)
View Answer

Answer: a
Explanation: Open is used for opening connection to ‘foo.txt’ in read-only mode.

advertisement

9. Which of the following code opens a connection to the file foo.txt, reads from it, and closes the connection when its done?
a) data <- read.csv(“foo.txt”)
b) data <- read.csvo(“foo.txt”)
c) data <- readonly.csv(“foo.txt”)
d) data <- getonly.csv(“foo.txt”)
View Answer

Answer: a
Explanation: Connections must be opened, then the are read from or written to, and then they are closed.

10. Which of the following opens connection to gz-compressed text file?
a) con <- gzfiles(“words.gz”)
b) con <- gzfile(“words.gz”)
c) con <- gzfile2(“words.gz”)
d) con <- gzfiles2(“words.gz”)
View Answer

Answer: b
Explanation: For more structured text data like CSV files or tab-delimited files, there are other functions like read.csv() or read.table().

Sanfoundry Global Education & Learning Series – R Programming Language.

Here’s the list of Best Reference Books in R Programming Language.

advertisement
To practice all areas of R Programming Language, Here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn