R Data Visualization Recipes
上QQ阅读APP看书,第一时间看更新

How does it works...

The first step performs that package check and installation thing introduced in Chapter 2, Plotting Two Continuous Variables. Conditional if statement will only run install.packages() if require(car) is NOT (!) true. Next, step 2 loads the package (library()) and asks for the Salaries data set documentation (?Salaries). Last step simply checks the first few rows by calling head(), while also checking if Salaries is already a data frame by using the class() function.

If, by any chance, you have found conditional so much useful that you going to use it a lot, consider making a function out of it. Try: check_install <- function(package_name) { if( !require(package_name) ) { install.packages( paste(package_name) ) }}