Challenge - 5 Problems
R Package Installer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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") }
Attempts:
2 left
💡 Hint
Think about what happens if the package is not installed yet.
✗ Incorrect
The code checks if 'ggplot2' is in the list of installed packages. If not, it installs it and prints 'Installed ggplot2'. Otherwise, it prints 'ggplot2 already installed'.
❓ Predict Output
intermediate2: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")Attempts:
2 left
💡 Hint
Try to install a package that does not exist on CRAN.
✗ Incorrect
R will warn that the package is not available because it cannot find it on CRAN or other repositories.
🔧 Debug
advanced2: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)
Attempts:
2 left
💡 Hint
Check how package names should be passed to install.packages.
✗ Incorrect
The package name must be a string in quotes. Without quotes, R treats dplyr as an object, causing an error.
🧠 Conceptual
advanced2: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?
Attempts:
2 left
💡 Hint
Think about where R looks to find packages.
✗ Incorrect
The 'repos' argument tells R which repository URL to use to find and download the package.
❓ Predict Output
expert2: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)
Attempts:
2 left
💡 Hint
Check how new_pkgs is calculated based on installed packages.
✗ Incorrect
The code checks which packages from the list are not installed yet and installs only those. The length of new_pkgs depends on the current system state.