Hide the in-function plot from R package [duplicate] - r

This question already has an answer here:
How can I suppress the creation of a plot while calling a function in R?
(1 answer)
Closed 6 years ago.
I am using the R package "GeoDE". When I use the function "chdirAnalysis", a figure will be plotted automatically, since there is a command "plot" in the source code of "chdirAnalysis". But I don't want that. How can I stop this?
A similar problem is to hide the in-function printed messages, and I've found the solution which is to use invisible
capture.output(value <- function_name(input))
That can help hide the output from "function_name", but this solution doesn't work on the plot.

Options:
Ask the maintainer to add a plot=FALSE option to the function (and maybe a verbose=FALSE option to stop the text outputs).
Edit the source for chdirAnalysis and remove the function call that does the plotting, or hide it behind a new plot=FALSE options. I think this is chdirplots, which is called but doesn't do anything with its return value. If you are doing this outside the GeoDE package source then you'll need to add the GeoDE::: prefix to any unexported GeoDE functions called by chdirAnalysis (such as chdirSig).
Make it plot to some dummy or throwaway graphics device file, as described in other questions and answers.

Related

R - Encrypt / Lock Down R Code and Package [duplicate]

This question already has answers here:
Protect/encrypt R package code for distribution [closed]
(2 answers)
Closed 5 years ago.
Is it possible to create an R package such that if I give it to a user, they could run all the functions within the package, but not be able to view any of the source code?
The two possible ways I can think of would be someone opening up the raw .R files within the package, or by typing the function name in the R console to print the R code text. So is there a way to encrypt the files or disable the function print calls for the functions?
Thanks
Luckily, there is no such functionality. If you want to hide your analysis or algorithm, perhaps you could use some proprietary software or write your code in a language which compiles (e.g. C++). Note that all software is reverse-engineerable. It's just a matter of motivation.

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.

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.

Update plots during for loop from within Rstudio? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Plotting during a loop in RStudio
I'm trying to monitor the status of a convergence loop, and I can't seem to get it to update the graph each time it iterates.
Here's some sample code:
print(plot(c(0,1)~c(0,100)))
for(i in seq(100)) {
Sys.sleep(.1)
print(points( runif(1)~i ))
}
Note that the graph only updates after everything's been plotted. I need it to update each loop iteration. I thought print would do that, but it's not working.
Update
This is an RStudio-specific problem, as it works properly in base R. Is there a way to force graphing in RStudio each loop iteration?
Start up a separate graphics device with X11() (or win() on windows?) and use that.
Although plots seem to update okay on my RStudio setup. My test is simply:
plot(1:10);for(i in 1:10){points(10-i,i);Sys.sleep(1)}
I see the first set of 10 points, then the next set appear at one second intervals, in the RStudio embedded graphics window.

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