Packages in R are libraries of built in functions and possibly some data sets. Packages are helpful since we do not have to write all functions from scratch as they are already written by some author for use.
In order to install packages in R, we use the following command:
For ex:
install.packages('randomForest') / install.packages("randomForest")
If you are using R, the R software will prompt you to select a CRAN mirror. You can choose any one and R will automatically download and install the package for you provided that package exists in the CRAN library.
Sometimes, source file does not exist in CRAN library. In that case, you can try to find the zip / tar file of the relevant package and download it on your machine. Then, you can install the package using following command:
install.packages('path_to_file', repos = NULL, type = 'source')
For example, if I have downloaded random forest package file named randomForest.tar.gz from the web, I can install random forest package as follows:
install.packages('/Users/admin/RPackages/randomForest.tar.gz', repos = NULL, type = 'source')
Once the package has been installed using via CRAN network / source, we need to 'load' the library to make sure that all the functions and data sets of the package are available to work with. For this, we use the following command:
load(packageName)
Remember that we do not enclose package name within quotes while loading the package. We only do that while installing the package.
For example:
library(randomForest)
Next in the series, we will see how to call datasets from packages in order to work with them.
In order to install packages in R, we use the following command:
install.packages('package_name') / install.packages("package_name")
Remember to put the name of the package to be installed within quotes
For ex:
install.packages('randomForest') / install.packages("randomForest")
If you are using R, the R software will prompt you to select a CRAN mirror. You can choose any one and R will automatically download and install the package for you provided that package exists in the CRAN library.
Sometimes, source file does not exist in CRAN library. In that case, you can try to find the zip / tar file of the relevant package and download it on your machine. Then, you can install the package using following command:
install.packages('path_to_file', repos = NULL, type = 'source')
For example, if I have downloaded random forest package file named randomForest.tar.gz from the web, I can install random forest package as follows:
install.packages('/Users/admin/RPackages/randomForest.tar.gz', repos = NULL, type = 'source')
Once the package has been installed using via CRAN network / source, we need to 'load' the library to make sure that all the functions and data sets of the package are available to work with. For this, we use the following command:
load(packageName)
Remember that we do not enclose package name within quotes while loading the package. We only do that while installing the package.
For example:
library(randomForest)
Next in the series, we will see how to call datasets from packages in order to work with them.
No comments:
Post a Comment