0
0
R Programmingprogramming~20 mins

Package installation (install.packages) in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
R Package Installer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this R code?
Consider the following R code that attempts to install a package and then check if it is installed. What will be the output?
R Programming
if (!"ggplot2" %in% installed.packages()[,"Package"]) {
  install.packages("ggplot2")
  print("Installed ggplot2")
} else {
  print("ggplot2 already installed")
}
AWarning: package ‘ggplot2’ is not available
Bggplot2 already installed
CError: object 'ggplot2' not found
DInstalled ggplot2
Attempts:
2 left
💡 Hint
Think about what happens if the package is not installed yet.
Predict Output
intermediate
2:00remaining
What happens when you run install.packages with a wrong package name?
What will be the output of this R code snippet?
R Programming
install.packages("nonexistentpackage123")
AWarning: package ‘nonexistentpackage123’ is not available
BInstallation succeeds silently
CError: could not find function "install.packages"
DThe package is installed but cannot be loaded
Attempts:
2 left
💡 Hint
Try to install a package that does not exist on CRAN.
🔧 Debug
advanced
2:00remaining
Why does this install.packages call fail?
This R code is intended to install the 'dplyr' package but fails with an error. What is the cause?
R Programming
install.packages(dplyr)
ANetwork connection error
BSyntax error: missing quotes around package name
Cinstall.packages does not accept package names as strings
Ddplyr package is already installed, so it fails
Attempts:
2 left
💡 Hint
Check how package names should be passed to install.packages.
🧠 Conceptual
advanced
2:00remaining
What does the 'repos' argument in install.packages do?
In R, what is the purpose of the 'repos' argument in the install.packages function?
AIt specifies the repository URL from which to download the package
BIt sets the local folder where the package will be installed
CIt defines the version of the package to install
DIt lists the dependencies to install along with the package
Attempts:
2 left
💡 Hint
Think about where R looks to find packages.
Predict Output
expert
2:00remaining
How many packages are installed after running this code?
Given the following R code, how many packages will be installed after it runs?
R Programming
pkgs <- c("ggplot2", "dplyr", "tidyr")
new_pkgs <- pkgs[!(pkgs %in% installed.packages()[,"Package"])]
if(length(new_pkgs)) install.packages(new_pkgs)
length(new_pkgs)
A0
B3
CDepends on which packages are already installed
D1
Attempts:
2 left
💡 Hint
Check how new_pkgs is calculated based on installed packages.