4

I have got function alpha() in packages scales and psych. The default call is scales, but I would like to change it. I want to make psych package higher priority - I mean if I call alpha() I want that R run this function from psych package, not scales.

Of course I know that I can use :: , but I don't want that.

How to do that in a simple way?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Tomasz Wojtas
  • 756
  • 2
  • 6
  • 12
  • 1
    Order of loading packages matters. If you don't want to use `::`, you will have to be careful of the order. This question has been asked many times. http://stackoverflow.com/search?q=%5Br%5D+masked+ Your best bet is `::`. – Roman Luštrik Apr 11 '16 at 19:27
  • See [How do I use functions in one R package masked by another package?](http://stackoverflow.com/q/9337716), `::` as Roman mentions is the best. If you feel the need to discuss this further, drop by the [R Public](http://chat.stackoverflow.com/rooms/25312/r-public) room. (But you need to get to 20 rep for that :(). – Bhargav Rao Apr 11 '16 at 19:35

1 Answers1

5

Three options:

(1) change the order in which you load the packages:

library(scales)
library(psych)

in this case, alpha refers to psych::alpha

(2) call the function like this:

psych::alpha

(3) load the packages in any order and set the function manually, e.g.

library(psych)
library(scales)
alpha = psych::alpha

in this case, even though you loaded psych before scales, the alpha function refers to psych::alpha

adn bps
  • 599
  • 4
  • 16