View the source of an builtin R package [duplicate] - r

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.

Related

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.

function not being added to NAMESPACE

I have a function that I'm trying to add to a package. I am generating the documentation via devtools::document(). The .Rd files for this and ~70 other functions are generated successfully, but this one function is not added to the namespace.
The file can be found at the following link, and perhaps importantly, is called truncate.distribution.r. I have many other functions with periods in the names, so I am almost certain that is not the problem.
However, as I was going through the NAMESPACE, I noticed this line S3method(truncate,distribution), and wondered if the similar name was a coincidence (i.e. comma, as opposed to period). I tried removing the period from the name, and re-generating the documentation and NAMESPACE, and it all worked just fine - that is, the function is exported with the package.
While the altered name works, I would like to learn why it failed and how I can prevent similar failures in the future. Also, I like the original name. :)
Anyone have any thoughts? Much appreciated.
So you guys are right, and it had to do with the periods in the names. The particular file that cause the problem for us was one where the first part of the name ("truncate."...) was already a base function, thus being interpreted as S3methods.
Thanks to all who answered. I'm not sure why I'm getting voted down - knowing not to use periods in function names is not inherent knowledge, nor is it expressly forbidden anywhere I looked (i.e. Hadley's, or Google's Style Guides).
I found one other potential cause of similar grief. My last line of Roxygen code had a typo in the #' #export command resulting in the same poor behavior

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.

R bindings for Mapnik?

I frequently find myself doing some analysis in R and then wanting to make a quick map. The standard plot() function does a reasonable job of quick, but I quickly find that I need to go to ggplot2 when I want to make something that looks nice or has more complex symbology requirements. Ggplot2 is great, but is sometimes cumbersome to convert a SpatialPolygonsDataFrame into the format required by Ggplot2. Ggplot2 can also be a tad slow when dealing with large maps that require specific projections.
It seems like I should be able to use Mapnik to plot spatial objects directly from R, but after exhausting my Google-fu, I cannot find any evidence of bindings. Rather than assume that such a thing doesn't exist, I thought I'd check here to see if anyone knows of an R - Mapnik binding.
The Mapnik FAQ explicitly mentions Python bindings -- as does the wiki -- with no mention of R, so I think you are correct that no (Mapnik-sponsored, at least) R bindings currently exist for Mapnik.
You might get a more satisfying (or at least more detailed) answer by asking on the Mapnik users list. They will know for certain if any projects exist to make R bindings for Mapnik, and if not, your interest may incite someone to investigate the possibility of generating bindings for R.
I would write the SpatialWotsitDataFrames to Shapefiles and then launch a Python Mapnik script. You could even use R to generate the Python script (package 'brew' is handy for making files from templates and inserting values form R).

Resources