Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load packages in R

Tags:

r

tm

I have successfully installed the tm package, which is located in: C:\Users\JustinLiang\Documents\R\win-library\3.0

After type library(), it shows me the R packages available list:

Packages in library ‘C:/Users/JustinLiang/Documents/R/win-library/3.0’:

tm Text Mining Package

Packages in library ‘C:/Program Files/R/R-3.0.2/library’:

however, when I try to load the package: library(tm), it shows me an error:

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘slam’
Error: package or namespace load failed for ‘tm’
like image 232
Jusleong Avatar asked Dec 11 '13 21:12

Jusleong


People also ask

Which function is used to load packages in R?

There are basically two extremely important functions when it comes down to R packages: install. packages() , which as you can expect, installs a given package. library() which loads packages, i.e. attaches them to the search list on your R workspace.

How do I load Mass packages in R?

library(MASS) Another way to load a package is to simply check the box next to the package name in the Packages panel in RStudio. When you use this method, you will notice that RStudio enters the Library( ) command in the Command console when you check the package box.


1 Answers

The package has to be first installed before you load the package using library(). To install any package, open the R or RStudio shell and execute the following

install.packages("tm",dependencies=TRUE)

This will ask you to select the mirror and it will install it for you. If you use RStudio, you can easily do it from the Tools menu as shown below (Tools -> Install Packages -> Name of the package you want to install). enter image description here

And then finally, you can invoke the library("name of the package installed") function.

like image 173
Desta Haileselassie Hagos Avatar answered Sep 22 '22 19:09

Desta Haileselassie Hagos