How to specify from which library a function is used? [duplicate] - r

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
R: Masked Functions
I am using the packages moments and fUnitRoots. Both of them have a function called "kurtosis" (to be more precise, the package fUnitRoots calls the package timeDate which also has the function "kurtosis"). They give very different results, because their formulas is slightly different. I want to use the function skewness from the library moments, but if the two libraries are loaded, the function used is the one from fUnitRoots.
How can I specify from which library I want the given function to be used, without unloading one of the libraries?

Use the :: operator. The syntax is package::name. So it would be moments::kurtosis.

Related

Meaning of :: syntax [duplicate]

This question already has answers here:
R: What do you call the :: and ::: operators and how do they differ?
(1 answer)
What are the double colons (::) in R?
(2 answers)
Closed 3 years ago.
I am new to R, when reading functions documentation how do I interpret ::?
How do I actually read the syntax?
readxl::read_excel()
Not sure if in R studio I can find any information about
In R there are different packages available,
"readxl" is one of them.
When you install a package, you are ready to use its functionalities.
If you just need a sporadic use of a few functions or data inside the
package you can access them with the notation packagename::functionname().
For example, since you have installed the readxl package, you can explore one of its functionality called read_excel() to import/read excel sheet.
Command to check what functions and data are contained in a package.
help(package = "packageName")

Loading rasterVis causes trouble in shift() of data.table. How to completely remove a loaded package from R? [duplicate]

This question already has answers here:
What does "The following object is masked from 'package:xxx'" mean?
(2 answers)
Closed 5 years ago.
In the stats package, there is a highly useful function called reorder().
In the gdata package, there is also a function called reorder().
How do I force reorder() from stats, not to be overwritten when loading the gdata package? Or, is there a way to reference which reorder() you want to use?
Use stats::reorder() to reference the version in stats.
From the Examples section of ?library:
## if you want to mask as little as possible, use
library(mypkg, pos = "package:base")
You can just use stats::reorder()

Error: Usage: rescale(x, newrange). where x is a numeric object and newrange is the new min and max [duplicate]

This question already has answers here:
What does "The following object is masked from 'package:xxx'" mean?
(2 answers)
Closed 5 years ago.
In the stats package, there is a highly useful function called reorder().
In the gdata package, there is also a function called reorder().
How do I force reorder() from stats, not to be overwritten when loading the gdata package? Or, is there a way to reference which reorder() you want to use?
Use stats::reorder() to reference the version in stats.
From the Examples section of ?library:
## if you want to mask as little as possible, use
library(mypkg, pos = "package:base")
You can just use stats::reorder()

List of functions of a package [duplicate]

This question already has answers here:
Show names of everything in a package
(4 answers)
Closed 5 years ago.
Is there an easy, friendly way to list all functions of a package without downloading those huge PDFs (package references)? I need this for getting me familiar with the package, finding proper functions etc.
I tried ?rjags but it doesn't do what I expected.
Load the package (for example the carpackage). Then use ls()
ls("package:car")
The closest thing I've been able to find for this is:
help(,"rjags")
The first parameter specifies the searched thing, second one specifies the package. By keeping only the second one, I hope to get all help pages that relate to that package. This is equivalent of
help(package = "rjags")
This might not work in general though, as in ?help the functionality of omitting the first parameter is described as
topic is not optional: if it is omitted R will give
If a package is specified, (text or, in interactive use only, HTML) information on the package, including hints/links to suitable help
topics.

Two functions with the same name in R [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Masked functions in R
R: Masked Functions
function naming conflicts
If I have two packages: A and B. Say there is function named funfun in A and there is function named funfun in B too. When I load A and B, how do I use the first funfun?
require(A)
require(B)
If I want to use funfun in A, how do I write this?
You can explictily refer to a package and function combination like this:
A::funfun
B::funfun
In unusual circumstances, you may have to refer to functions that are not exported in the namespace, in which case you need to use:
A:::funfun
B:::funfun
(But this would be unusual, and since non-exported functions do not form part of the package API, these functions could change without warning in subsequent releases of a package.)

Resources