List of functions of a package [duplicate] - r

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.

Related

How to put units inside roxygen [duplicate]

This question already has answers here:
Mathematical notion/superscripts in Rd files
(2 answers)
Closed last year.
I am docummenting a dataset using roxygen2 (for my package development). I am trying to put cube meter (m^2) as a unit for one of my variable but it remains the same (m^2) when I am trying to see the documentation ?data.
How can I generate units inside roxygen2?
Thank you
You should use this line:
\ifelse{html}{\out{m<sup>2</sup>}}{\eqn{m^2}}
You need to keep in mind that Roxygen is used to produce by HTML and PDF versions of your documentation. The first statement in the ifelse will be for the HTML, the second will be for PDF.

Can you manage R package conflicts by explicitly referencing packages in function calls? [duplicate]

This question already has an answer here:
Is it a good practice to call functions in a package via ::
(1 answer)
Closed 2 years ago.
I don't like that you can have R package conflicts in function calls, or namespace collisions. For instance, plyr and dplyr have functions with the same names, so if you have them both loaded you need to know which functions these are so you can attach and detach packages appropriately. Sure, in this example, dplyr is meant to replace plyr which is why conflicts emerge, but this can hypothetically happen with any number of packages. What a nightmare! This isn't an issue in Python because you prefix the function call with the name/alias of the package you imported, e.g. pd.melt().
So, my question is: is there any equivalent way to do this in R? Can you manage package conflicts by explicitly referencing the package in a function call?
I see someone asked basically the same question here six years ago, and it remains unsolved. The only answer offered is to check out the conflicted package. This is a start, lending transparency to the conflicts, but you have to dig through the package to find anything better than that (update: see comments below to find references to which features of the package are most useful for this issue).
Update
There are a number of solutions in the comments, including those found in this post. But, while that post answers my question, it doesn't ask it, which might be part of the reason I didn't find it in my search. It starts with the assumption that you already know the quick and dirty solution of using the proper prefix syntax. So, it might be best to leave this post up as a non-duplicate for future searchers.
Just prefix the package name with a double colon:
<package>::<function>()
For instance:
ggplot2::ggplot(data=data, ggplot2::aes(x=x)) +
ggplot2::geom_histogram()

How can I change/replace some functions with some other functions within a package?

I am trying to make some changes or replace some functions with other ones within the R package rodd. I have downloaded and extracted the source codes. They are in different files and some of them need editing. How can I do it in a proper way?
I searched on the internet. I only found cases who need one single change in a function within a package. But in my case, the package rodd needs some more changes and also replacing some functions with the original ones. I also need to mention that I need to make a 2 dimensional (for the control variable X) version of the package. So I am still not sure which changes fit my needs and each time I need to make some changes and see which changes solve the problem. I also need to have both the actual version and the edited version of the package.
Any ideas/suggestions are appreciated.
tpopt(x, ...)
I would also mention I need to make some changes in the procedure (other functions) which result in the function tpopt, not the function tpopt itself.

Rstudio own Method/Function minihelp [duplicate]

This question already has answers here:
Is it possible to get RStudio to show function arguments and descriptions for custom functions?
(2 answers)
Closed 5 years ago.
If I write a method or function, how can i get that "minihelp" (whose special term I dont know) which is shown while writing a function?
E.g. for "plot" it exists; Type
>plot([TAB]
then the following shows in a kind of "Tooltip"
x=
y=
... =
and if you choose for example "x", then after a second the following tooltip shows:
x
the coordinates of points in the plot. Alternatively, a single plotting
structure, function or any R object with a plot method can be provided.
Some info but not crucial to the problem: I am working with Rstudio and writing multiple S4 generics/methods for the class ExpressionSet.
Sadly I can't manage to find a cool google keyword, so I hope you can help me out!
Edith:
The following question is about the same as mine but i have still the ongoing problem that I already wrote a package, every function is documented with roxygen, I followed hadleys descriptions. Nevertheless, the tooltips do not show up.
In the linked question it is said that "help files must be generated" - which I assume are generated as ?myS4Method is showing the appropriate help pages. Any ideas?
The functionality you are looking for comes from the way RStudio parses the documentation of packages. If you create a package, you can add Roxygen comments to your functions or classes. These comments are then parsed when you create the package into documentation files that you see as the help for a function.
If you run the command ?plot you will see a list of Arguments. These are the parameters that can be passed to the function and that is what the tooltip in RStudio is telling you about.
To get RStudio to give you info about the functions you are using, you should bundle your S4 classes into a package (Hadley Wickham's tutorial) and make sure they are correctly documented. RStudio will take care of the rest.

View the source of an builtin R package [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
View the source of an R package
I want to see the source code of stats::reorder.
This answer seems not apply to built in packages which are compiled to bytecode:
> stats::reorder
function (x, ...)
UseMethod("reorder")
>bytecode: 0x103321718<
>environment: namespace:stats<
This has nothing to do with reorder being compiled to bytecode and everything to do with it being a generic function.
My answer here elaborates on this.
But specifically for this situation if you want to see the code you can use
# Find what methods are available for reorder
methods(reorder)
# Attempt to check out the code for reorder.default
reorder.default
# Use getAnywhere to view code regardless of if it is exported
getAnywhere(reorder.default)
As others have said, you want methods(reorder). But for your mode general question, the best way is to download the source code of R, and search the code with grep. You can also browse the code online but it's not always obvious in which file a particular function might live.
This isn't a matter of compilation, what you're seeing is the result of the fact that reorder is written to do different things depending on the class of what you want to reorder. There are separate reorder functions for different possible options, and you can list them by calling methods(reorder). You can then examine the source of whichever one is appropriate.

Resources