How to disable package without restarting R? [duplicate] - r

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to unload a package without restarting R?
To load a package into R we can go library(.) or require(.). How do I disable a package during a coding session. I want something that's the opposite of require(.).

I think maybe you're looking for detach(package:splines, unload = TRUE).
As you might gather from the comments below, be sure to read carefully the Details section of ?detach to make sure you know exactly what will happen when using this with or without the unload and force arguments.

Related

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()

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.

R - how to "save" the loaded packages [duplicate]

This question already has answers here:
How to load packages in R automatically?
(4 answers)
Closed 5 years ago.
Recently moved over to R (from MATLAB) - enjoying it…
…However, every time I close R down, I lose all the packages which I loaded in my previous session, and I need to load them up again (I use a Mac OS).
I know there is a way to save the current loaded packages, and have them load up automatically each time I reopen R - I have seen the answer in a few places, but I don't understand the terminology.
Can someone kindly walk me through it… Click by click?
With appreciation
I do it with my .Rprofile file which resides in my default working directory. (I also un-hide my dot-files so it's easy to get at it.) I use Sys.setenv() to maintain the needed PATH environment variable and then load my packages with:
require(lattice)
require(sos)
require(rms)
Demonstrations of how to edit text-files and control of system resources are not really on-topic in SO. You should be able to teach yourself those skills by searching,
It's kind of amusing that one of the most highly voted R questions is closed as not constructive: Expert R users, what's in your .Rprofile? I will admit that technically it probably does violate the stated rules, but you may find it useful, both for the information and to see what sort of question is considered "on- (or off-)topic" in SO.

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.

List all packages available on CRAN to console [duplicate]

This question already has answers here:
Names of R's available packages
(4 answers)
Closed 9 years ago.
Would like to get a list of all packages available on CRAN to the windows console. I know that it's gotta be pretty easy because on the windows gui there's an manu option to click install, at which time another menu interface pops up with all packages available on CRAN. If the menu were a function (which it probably is I just don't know what it is) I'd look at the code and figure out how they get that list.
So what you see here: (packages alphabetical LINK) I'd like to get to the console so I can assign it to an object.
?available.packages did not appear in the results of your search? You did search before asking, didn't you? ;-)

Resources