This question already has answers here:
How to use an R script from GitHub?
(4 answers)
Install R-Package from Github
(3 answers)
Closed 2 years ago.
I'm using a package from github and functions in it are not... connected.
The main file has a function but to make that function work i need to run 4 diffrent files (3 files got a lot of functions in them and 1 has class).
Do we have any option to import whole scripts (with all the functions, classes, variables) on top of my main file so they will appear in my enviroment?
for exmaple in file "foo.R" i have a function "food = function(...)" so i do smth like
from foo.R import food
result <- 2*food(a,b,c)
or
from foo.R import *
result <- 2*foo.food(a,b,c)
like in python?
I think you should take a look at the combination of here + source. Basically, what you can do is the following:
library(here)
source(here::here('R', 'file_that_contains_a_lot_of_functions.R'))
In that way, you will get all the functions from file_that_contains_a_lot_of_functions.R in the GlobalEnviroment make it easy to work with them.
PS1: the 'R' above is because I am assuming you downloaded a mirror of the library from Github, and you are taking the functions from the R folder.
PS2: it also assumed that you generated a project at the level of the main folder of the package. What I also do is to generate an extra folder my_folder where I store everything that I create to do not disturb the workflow of the original package.
use the command source() and put in the file to run - then you will have access to all objects within.
source("path/to/your/file.R")
Related
This question already has answers here:
Load R package from character string
(2 answers)
Closed 6 years ago.
I would like to install/load packages from a different location that is default. I dont have admin privileges so I cant access my .rprofile from the control panel.
My thought was I could just make a different library function, so I dont have to type a lib.loc statement every time i want to install/load a function. This is what i think the "liBerty" function should look like.
liBerty <- function(a) {
require(a,lib.loc="C:\\Users\\bert\\Documents\\rpackages" )
}
liBerty(tm)
The error I am getting states "there is no package 'a'.". Is there a way i can write this function to accomplish my task?
The function needs to also be modified for installing packages
install.Bertages<-function(b){
install.packages(b,lib="C:\\Users\\bert\\Documents\\rpackages")
}
liBerty<-function(a){
require(a,lib.loc="C:\\Users\\bert\\Documents\\rpackages",
character.only=TRUE )
}
install.Bertages("lubridate")
liBerty("lubridate")
This question already has answers here:
How to find all functions in an R package?
(6 answers)
Closed 7 years ago.
I would like to know if there is a command, using which one can view all the functions that are built into an R package.
For example, let's say I loaded a package into environment:
require(dplyr)
Now, I would like to get a list of all the functions present in the dplyr package.
Is there any way to get such a list?
You can use lsf.str.
For instance:
lsf.str("package:dplyr")
To list all objects in the package use ls
ls("package:dplyr")
Note that the package must be attached.
To see the list of currently loaded packages use
search()
Alternatively calling the help would also do, even if the package is not attached:
help(package = dplyr)
Finally, you can use RStudio which provides an autocomplete function. So, for instance, typing dplyr:: in the console or while editing a file will result in a popup list of all dplyr functions/objects.
This question already has answers here:
Possible to create Rd help files for objects not in a package?
(7 answers)
Closed 7 years ago.
I need to generate documentation for a collection of R programs. Unfortunately, building a package based on the source code is not an option (I know how to do that, and I have already experimented with RStudio, roxygen2, and packages, and it works like a charm). Can I use roxygen2 to to generate documentation from the R source code without building a package in a way similar to how doxygen works with C++? If not, are there other options for documenting R code that do not rely on packages?
If your only after the documentation, devtools::document() will build the documentation files without building the package.
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Better explanation of when to use Imports/Depends
(4 answers)
Closed 4 years ago.
I am developing an R package that uses third party functions
available in the Bioconductor package "methyilumi"
In the code for my R package at the very beginning I import methylumi
with library(methylumi).
During the development (I use roxygen2 and devtools) everything works fine.
However, when I install the package and run my functions, I get the error:
could not find function "methylumIDAT".
Of course everything is solved if I import the package manually, but how can I make
so that methylumi is available whenever I load my own package?
Since you are using devtools, you can add
devtools::use_package("methyilumi")
in the console, and call methyilumi::methylumIDAT in the body of your function. That way, the package is automatically listed in Imports in the DESCRIPTION file.
This sections gives the instructions for several different cases:
http://r-pkgs.had.co.nz/namespace.html#imports
This is done with the NAMESPACE file and also noted in the DESCRIPTION file. There are a few ways to import a function in NAMESPACE, but the simplest is just importFrom("[PACKAGE_NAME]",[FUNCTION_NAME). Then, in DESCRIPTION, add the package name to imports.
See this very good tutorial from Friedrich Leisch.
http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to properly use functions from other packages in a R package
load data set automatically
I've built an R package and am now testing it. It requires several packages like scatterplot3d, gdata, etc.
How can I get those packages to load automatically, when someone loads my package?
Thanks!
Edit Re Comments: I've already set imports in the Description and I've set the namespaces file. I know this works because the examples I put in work when I do R CMD Check. However, if I just load up R, type library(mypackage) it gives me an error.
Edit: Solved, I moved the packages I had in the imports section to the depends section. Thank you!