250+ TOP MCQs on Packages and Answers

R Programming Language Multiple Choice Questions on “Packages ”.

1. What will be the output of the following R code?

install.packages(c("devtools", "roxygen2"))

a) Develops the tools
b) Exits R studio
c) Installs the given packages
d) Nothing happens

Answer: c
Clarification: Make sure you have the latest version of R and then run the above code to get the packages you’ll need. It installs the given packages. Confirm that you have a recent version of RStudio.

2. Which of the following is the formal requirement?
a) Package
b) Function
c) Letters
d) Interfaces

Answer: c
Clarification: There are three formal requirements: the name can only consist of letters, numbers and periods, i.e., it must start with the letter and it should not end with a period.

3. To start with the new package in RStudio, double-click the pkgname.Rproj file that _______
a) Delete()
b) Create()
c) Run()
d) Exit()

Answer: b
Clarification: To get started with your new package in RStudio, double-click the pkgname.Rproj file that create() just made. This will open a new RStudio project for your package. Projects are the way to develop packages.

4. If you have an existing package that doesn’t have an .Rproj file, you can use devtools for the use_rstudio(“_____/to/package”) to add it.
a) Path
b) Package
c) Function
d) Class

Answer: a
Clarification: If you have an existing package that doesn’t have an .Rproj file, you can use devtools for the use_rstudio(“path/to/package”) to add it.

5. An .Rproj file is a ____ file.
a) Pdf
b) Jpeg
c) Text
d) Png

Answer: c
Clarification: An .Rproj file is a text file. If you don’t use RStudio, you can get many of the benefits by starting a new R session and ensuring that the directory is set to the package directory.

6. A bundled package is a package that’s been compressed into a ______ file.
a) Double
b) Triple
c) Single
d) No file

Answer: c
Clarification: A bundled package is a package that’s been compressed into a single file. A source package is just a directory with components like R/, DESCRIPTION, and so on.

7. ________ are built in R so that you get HTML.
a) Vignettes
b) Vighnaants
c) Bignats
d) Viddnets

Answer: a
Clarification: Vignettes are built for getting the HTML and PDF output instead of Markdown or LaTeX input. A bundled package is a package that’s been compressed into a single file.

8. Which of the following package has temporary files?
a) Single
b) Source
c) Bundle
d) Double

Answer: b
Clarification: Source package might contain temporary files used to save time during development and the compilation artifacts in a source. These will be never found in a bundle.

9. files listed in the Rbuildignore are not included in the ______
a) single
b) source
c) bundle
d) double

Answer: c
Clarification: Files listed in the Rbuildignore were not included in the bundle. .Rbuildignore prevents files from the src package and appearing in the bundled package. It allows you to have some extra directories in your source package that will not be included in the package bundle.

10. .Rbuildignore prevents files in the ___________ package from appearing in the bundled package.
a) single
b) source
c) bundle
d) double

Answer: b
Clarification: .Rbuildignore prevents files from the source package and appearing in the bundled package. It allows to have some extra directories in your source package that will not be included in the package bundle.

250+ TOP MCQs on Overview of R and Answers

R Programming Language Multiple Choice Questions on “Overview of R”.

1. They primary R system is available from the ______
a) CRAN
b) CRWO
c) GNU
d) CRDO

Answer: a
Clarification: CRAN stands for Comprehensive R Archive Network.

2. Point out the wrong statement?
a) Key feature of R was that its syntax is very similar to S
b) R runs only on Windows computing platform and operating system
c) R has been reported to be running on modern tablets, phones, PDAs, and game consoles
d) R functionality is divided into a number of Packages

Answer: b
Clarification: R runs on almost any standard computing platform and operating system.

3. R functionality is divided into a number of ________
a) Packages
b) Functions
c) Domains
d) Classes

Answer: a
Clarification: CRAN also hosts many add-on packages that can be used to extend the functionality of R.

4. Which Package contains most fundamental functions to run R?
a) root
b) child
c) base
d) parent

Answer: c
Clarification: base package in R contains the most fundamental functions.

5. Point out the wrong statement?
a) One nice feature that R shares with many popular open source projects is frequent releases
b) R has sophisticated graphics capabilities
c) S’s base graphics system allows for very fine control over essentially every aspect of a plot or graph
d) All of the mentioned

Answer: c
Clarification: R has maintained the original S philosophy, which is that it provides a language that is both useful for interactive work, but contains a powerful programming language for developing new tools.

6. Which of the following is a base package for R language?
a) util
b) lang
c) tools
d) spatial

Answer: c
Clarification: The other packages contained in the “base” system include utils, stats, datasets, graphics, grDevices, grid, methods, parallel, compiler, splines, tcltk, stats4.

7. Which of the following is “Recommended” package in R?
a) util
b) lang
c) stats
d) spatial

Answer: d
Clarification: “Recommended” packages also include boot, class, cluster, codetools, foreign, KernSmooth, lattice, mgcv, nlme, rpart, survival, MASS, nnet, Matrix.

8. What is the output of getOption(“defaultPackages”) in R studio?
a) Installs a new package
b) Shows default packages in R
c) Error
d) Nothing will print

Answer: b
Clarification: There are base packages (which come with R automatically), and contributed packages. The base packages are maintained by a select group of volunteers called R Core. In addition to the base packages, there are over ten thousand additional contributed packages written by individuals all over the world.

9. Advanced users can write ___ code to manipulate R objects directly.
a) C, C++
b) C++, Java
c) Java, C
d) Java

Answer: a
Clarification: For computationally-intensive tasks, C, C++ and Fortran code can be linked and called at run time.

10. Which of the following is used for Statistical analysis in R language?
a) RStudio
b) Studio
c) Heck
d) KStudio

Answer: a
Clarification: RStudio is a web application framework for R.

250+ TOP MCQs on Data Types and Answers

R Programming Language Multiple Choice Questions on “Data Types”.

1. Accessing elements is achieved through a process called ________
a) Indexing
b) Outdexing
c) Highlighting
d) Scrapping

Answer: a
Clarification: Accessing elements is achieved through a process called indexing. Indexing may be done by a vector of positive integers and negative integers to indicate inclusion.

2. Which are indexed by either row or column using a specific name or number?
a) Datasets
b) Data frames
c) Data
d) Functions

Answer: b
Clarification: Data frames can be indexed by either row or column using a specific name (that corresponds to either the row or column) or a number.

3. What should we use to access elements with a value greater than five?
a) Subsetting commands
b) Use functions
c) Packages
d) Interfaces

Answer: a
Clarification: To access elements with a value greater than five we can use some subsetting commands and logical operators to produce the desired result.

4. Lists can be created using the _______ function.
a) Matrix.li
b) Matrix.lists
c) Lists.matric
d) List

Answer: d
Clarification: Lists can be created using the list function. Like data frames, they can incorporate a mixture of modes into the one list and each component can be of a different length or size.

5. First component of the list can be accessed by _____________
a) Name of the component
b) List name
c) Function
d) Package

Answer: a
Clarification: There are a number of ways of accessing the first component of a list. We can either access it through the name of that component (if names are assigned) or by using a number corresponding to the position of the component.

6. How can we access the first component of the list?
a) Number of the position
b) Function
c) Package
d) Tools

Answer: a
Clarification: There are a number of ways of accessing the first component of a list. We can either access it through the name of that component (if names are assigned) or by using a number corresponding to the position the component.

7. The first component can be accessed using __________ operator.
a) Intraction
b) Extraction
c) AND
d) OR

Answer: b
Clarification: There are a number of ways of accessing the first component of a list. We can either access it through the name of that component (if names are assigned) or by using a number corresponding to the position the component corresponds to. The former approach can be performed using subsetting ([[]]) or alternatively, by the extraction operator ($).

8. To extract a sublist, we use _________ brackets.
a) Flower
b) Square
c) Double
d) Single

Answer: d
Clarification: To extract a sublist, we use single brackets. There are a number of ways of accessing the first component of a list.

9. The length of a list is ______ to the number of components in that list.
a) Double
b) Equal
c) Triple
d) One fourth

Answer: b
Clarification: The length of a list is equal to the number of components in that list. Lists can be created using the list function. Like data frames, they can incorporate a mixture of modes into the one list and each component can be of a different length or size.

10. Which function can be used to determine the names assigned to a list?
a) Names
b) Name
c) Nam
d) Nem

Answer: a
Clarification: To determine the names assigned to a list, the names function can be used. Lists can be created using the list function. Like data frames, they can incorporate a mixture of modes into the one list and each component can be of a different length or size.

11. Joining two lists can be achieved either using the _________ function.
a) Concat
b) Join
c) Reduce
d) Delete

Answer: a
Clarification: Joining two lists can be achieved either using the concatenation function or the append function.

12. Which function gives the list as output?
a) Spline
b) Matrix
c) Vector
d) Alphabet

Answer: a
Clarification: There are also many functions within R that produce a list as output. Examples of these functions include spline(), density() and locator().Joining two lists can be achieved either using the concatenation function or the append function.

13. Density function gives output as ________
a) Matrix
b) Lists
c) Vector
d) Number

Answer: b
Clarification: There are also many functions within R that produce a list as output. Examples of these functions include spline(), density() and locator().

14. Locator function gives output as ___________
a) Matrix
b) Lists
c) Vector
d) Number

Answer: b
Clarification: To extract a sublist, we use single brackets. There are a number of ways of accessing the first component of a list. There are also many functions within R that produce a list as output. Examples of these functions include spline(), density() and locator().

15. The _________ function returns a list of densities (y) corresponding to bin values (x).
a) Spline
b) Density
c) Lists
d) Locator

Answer: a
Clarification: The spline function returns a list of densities (y) corresponding to bin values (x). These can be passed to the plot routine to produce a line graph of the density.

250+ TOP MCQs on Functions and Answers

R Programming Multiple Choice Questions & Answers focuses on “Functions”.

1. What will be the output of the following R code snippet?

 > paste("a", "b", se = ":")

a) “a+b”
b) “a=b”
c) “a b :”
d) none of the mentioned

Answer: d
Clarification: With the paste() function, the arguments sep and collapse must be named explicitly and in full if the default values are not going to be used.

2. Point out the correct statement?
a) In R, a function is an object which has the mode function
b) R interpreter is able to pass control to the function, along with arguments that may be necessary for the function to accomplish the actions that are desired
c) Functions are also often written when code must be shared with others or the public
d) All of the mentioned

Answer: d
Clarification: An argument list is a comma separated list of formal arguments.

3. The __________ function returns a list of all the formal arguments of a function.
a) formals()
b) funct()
c) formal()
d) fun()

Answer: a
Clarification: Functions have named arguments which can optionally have default values.

4. What will be the output of the following R code snippet?

> f <- function(num = 1) {
+        hello <- "Hello, world!n"
+        for(i in seq_len(num)) {
+                cat(hello)
+         }
+         chars <- nchar(hello) * num
+         chars
+ }
> f()

a)

b)

c)

d) Error

Answer: a
Clarification: The formal arguments are the arguments included in the function definition.

5. Point out the wrong statement?
a) A formal argument can be a symbol, a statement of the form ‘symbol = expression’, or the special formal argument
b) The first component of the function declaration is the keyword function
c) The value returned by the call to function is not a function
d) Functions are also often written when code must be shared with others or the public

Answer: a
Clarification: The value returned by the call to function is a function.

6. You can check to see whether an R object is NULL with the _________ function.
a) is.null()
b) is.nullobj()
c) null()
d) as.nullobj()

Answer: a
Clarification: It is sometimes useful to allow an argument to take the NULL value, which might indicate that the function should take some specific action.

7. Which of the following code will print NULL?
a) > args(paste)
b) > arg(paste)
c) > args(pastebin)
d) > arg(bin)

Answer: a
Clarification: One catch with … is that any arguments that appear after … on the argument list must be named explicitly and cannot be partially matched or matched positionally.

8. What will be the output of the following R code snippet?

> f <- function(a, b) {
+       a^2
+ }
> f(2)

a) 4
b) 3
c) 2
d) 5

Answer: a
Clarification: This function never actually uses the argument b, so calling f(2) will not produce an error because the 2 gets positionally matched to a.

9. What will be the output of the following R code snippet?

 > paste("a", "b", sep = ":")

a) “a+b”
b) “a=b”
c) “a:b”
d) a*b

Answer: c
Clarification: With the paste() function, the arguments sep and collapse must be named explicitly and in full if the default values are not going to be used.

10. What will be the output of the following R code snippet?

> f <- function(a, b) {
+              print(a)
+              print(b)
+ }
> f(45)

a) 32
b) 42
c) 52
d) 45

Answer: d
Clarification: Arguments to functions are evaluated lazily, so they are evaluated only as needed in the body of the function.

250+ TOP MCQs on R Profiler and Answers

R Programming Language Multiple Choice Questions on “R Profiler”.

1. ________ is a systematic way to examine how much time is spent in different parts of a program.
a) Profiling
b) Monitoring
c) Logging
d) Debugging

Answer: a
Clarification: Sometimes profiling becomes necessary as a project grows and layers of code are placed on top of each other.

2. Point out the correct statement?
a) The Rprofiler() function starts the profiler in R
b) Using system.time() allows you to test certain functions or code blocks to see if they are taking excessive amounts of time
c) R must not be compiled with profiler support
d) Rprofiler() tabulates how much time is spent inside each function

Answer: b
Clarification: However, this approach assumes that you already know where the problem is and can call system.time() on it that piece of code.

3. R comes with a ________ to help you optimize your code and improve its performance.
a) debugger
b) monitor
c) browser
d) profiler

Answer: a
Clarification: In general, it’s usually a bad idea to focus on optimizing your code at the very beginning of development.

4. The _______ function computes the time (in seconds) needed to execute an expression.
a) system.timedeb()
b) system.time()
c) system.datetime()
d) system.deb()

Answer: b
Clarification: They system.time() function takes an arbitrary R expression as input and returns the amount of time taken to evaluate the expression.

5. Point out the correct statement?
a) Rprofiler() tabulates how much time is spent inside each function
b) Rprof() keeps track of the function call stack at regularly sampled intervals
c) By default, the profiler samples the function call stack every 2 seconds
d) R must not be compiled with profiler support

Answer: b
Clarification: The profiler is started by calling the Rprof() function.

6. system.time function returns an object of class _______ which contains two useful bits of information.
a) debug_time
b) proc_time
c) procedure_time
d) date.time_time

Answer: b
Clarification: if there’s an error, gives the time until the error occurred.

7. _________ time is time charged to the CPU(s) for the R expression.
a) elapsed
b) user
c) response
d) monitor

Answer: a
Clarification: Usually, the user time and elapsed time are relatively close, for straight computing tasks.

8. The elapsed time may be ________ than the user time if your machine has multiple cores/processors.
a) smaller
b) greater
c) equal to
d) null

Answer: a
Clarification: The elapsed time may be greater than the user time if the CPU spends a lot of time waiting around.

9. Parallel processing is done via __________ package can make the elapsed time smaller than the user time.
a) parallel
b) statistics
c) distributed
d) symmetry

Answer: a
Clarification: When you have multiple processors/- cores/machines working in parallel, the amount of time that the collection of CPUs spends working on a problem is the same as with a single CPU, but because they are operating in parallel, there is a savings in elapsed time.

10. You can time ________ expressions by wrapping them in curly braces within the call to system.time().
a) smaller
b) longer
c) error
d) grater

Answer: b
Clarification: If your expression is getting pretty long (more than 2 or 3 lines), it might be better to either break it into smaller pieces or to use the profiler.

250+ TOP MCQs on Packages and Answers

R Programming Language Multiple Choice Questions on “Packages ”.

1. _______ is not useful when developing a package since you have to install the package first.
a) Function
b) Library
c) Interface
d) Class

Answer: b
Clarification: library() is not useful when developing a package since you have to install the package first. A library is a simple directory containing installed packages.

2. Which function is used for seeing currently active libraries?
a) Curlib()
b) Currlib()
c) .libpaths()
d) Pathlibr()

Answer: c
Clarification: A library is simply a directory containing installed packages. Everyone can use the dot libPaths() for seeing which libraries are currently active.

3. Which function is used for loading packages?
a) Library
b) Interface
c) Loader
d) Linker

Answer: a
Clarification: library() function is used to load a package. library() is not useful when we are developing a package since you have to install the package first. A library is a simple directory containing installed packages.

4. The job of the __________ file is to store important metadata about your package.
a) Description
b) Interface
c) Thinker
d) Loader

Answer: a
Clarification: The job of the DESCRIPTION file is to store the metadata about your package. When you first start writing packages, you’ll mostly use these metadata to record what packages are needed to run your package.

5. DCF is an abbreviation for__________
a) Debian control function
b) Differentiative common function
c) Debian control format
d) Debian common format

Answer: c
Clarification: DESCRIPTION uses a very simple file format called DCF, the Debian control format. When you first start writing packages, you’ll mostly use these metadata to record what packages are needed to run your package.

6. Which of the following is most important when releasing the package?
a) Versioning
b) Developing
c) Redundancy
d) Functioning

Answer: a
Clarification: Versioning is most important when you release your package. Usually, people don’t have exactly the same versions of packages installed that you do.

7. Which of the following is called a one-line description of the package?
a) Function
b) Title
c) Interface
d) Class

Answer: b
Clarification: Title is a one-line description of the package, and is often also shown in package listing. It should be plain text, capitalised like a title, and NOT end in a period.

8. To release a package to _____ you must pick a standard license.
a) R
b) CRAN
c) CRON
d) Studio

Answer: b
Clarification: To release your package to CRAN, you must pick a standard license. Otherwise, it’s difficult for CRAN to determine whether or not it’s legal to distribute your package.

9. _____ package version is the sequence of atleast two integers separated by either. or -.
a) Java
b) C
c) R
d) Python

Answer: c
Clarification: R package version is the sequence of atleast two integers separated by either. or -. When you first start writing packages, you’ll mostly use these metadata to record what packages are needed to run your package.

10. The ________ number of your package increases with subsequent releases of a package.
a) Function
b) Studio
c) Version
d) Sequence

Answer: c
Clarification: The version number of your package increases with subsequent releases of a package, but it’s more than just an incrementing the counter of the way the number changes with each release can convey information.

11. Which of the following is one of the most important aspects of a good package?
a) Title
b) Description
c) Documentation
d) Libraries

Answer: c
Clarification: Documentation is one of the most important aspects of a good package. Without it, users won’t know how to use your package. Documentation is very much useful for the future.

12. ___________ are the most commonly documented object.
a) Interface
b) Class
c) Functions
d) Libraries

Answer: c
Clarification: Function is very most commonly documented object. The introduction block, most functions have three tags namely @param, @examples and @return.