Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load a function from a specific package

I'm loading two R packages Hmisc and TeachingDemos, which both contain a function called subplot(). I load the package Hmisc first and it seems that afterwards the subplot()-function from Hmisc is used. This happens even when I load the library TeachingDemos first.

How can I use the function subplot() from the TeachingDemos package, even if the Hmisc package is also loaded?

like image 989
John Garreth Avatar asked Sep 06 '13 19:09

John Garreth


People also ask

How do you set a function for a package in R?

Every time you start a new R session you'll need to load the packages/libraries that contain functions you want to use, using either library() or require() . If you load a package with the same function name as in another package, you can use packageName::functionName() to call the function directly.

Which function is import package in R?

import: An Import Mechanism for R The syntax allows for importing multiple objects from a package with a single command in an expressive way. The import package bridges some of the gap between using library (or require ) and direct (single-object) imports.


1 Answers

You can use the :: operator to specify which function to use like this...

TeachingDemos::subplot()
like image 170
Simon O'Hanlon Avatar answered Sep 17 '22 20:09

Simon O'Hanlon