I am trying to install a package from my own repository in order to test if the functions work. The link to the repository is here: https://github.com/hharder74/SampleMeansII. When I try to install it using the following code:
devtools::install_github("hharder74/SampleMeansII")
I get the following error:
Error: Failed to install 'unknown package' from GitHub: HTTP error 404. Not Found Did you spell the repo owner (`hharder74`) and repo name (`SampleMeansII`) correctly? - If spelling is correct, check that you have the required permissions to access the repo.
I am really confused on where this error is coming from. This is my first time trying to upload a package to GitHub, and I just wanted to check if the package can be installed before I turned it in to my teacher. Here is a bit of code to test the functions if anyone needs it:
vec <- runif(100)
sample_mean(vec, 50)
many_sample_means(vec, reps = 10, n = 50)
sample_means_ns(vec, reps = 10, ns = c(5, 50, 500))
You have not yet created a package. You've just created some files with R code in them. An R package has a very particular structure that includes things like a DESCRIPTION file and a NAMESPACE file. In theory you could create these yourself, but often it's easier to use things like devtools::create and roxygen to create them for you. Or if you are using RStudio, you can create a new R Package project with default versions of these files.
To add a DESCRIPTION File, try running
usethis::use_description()
That will fill in defaults you can change.
Then you will need to create a NAMESPACE file. If you just want to make all the functions you define inside your R files to be available outside the pacakge, you can just put
exportPattern("^[[:alpha:]]+")
in that file and that should work.
You might also consider following guides like thoses http://r-pkgs.had.co.nz/package.html or https://swcarpentry.github.io/r-novice-inflammation/08-making-packages-R/ for a better overview on creating a package.
Once your repo looks like a proper R package, then you can use devtools::install_github to install it.
Note that github can be useful for tracking changes to any types of files. You may perform an analysis in an R script that you would like to track changes for and save that on github but it may not make sense to turn that analysis script into a packages. You generally make packages when you want to reuse functions or data across different projects then those projects can install and load your package. So not all R code lives inside an R package, but devtools::install_github can only be used to install actual packages.
Related
I have some problems with creating package, can you please spot my mistake?
I followed instruction below :
1.Create functions I want in my package
2.Open new project -> R package
3.Create as many R documentation as many functions I implemented, and then put them into man folder
4.Press Ctr+Shift+B to install package.
The warning I'm facing is
Warning: C:/Program Files/R/R-3.6.3/library/mypackage/man/myfun2.Rd:62: All text must be in a section
I search internet about solution to that problem but I found only involved instructions containing other approach. Is there possibility how to fix this ? Or other approach with using other packages is crucial (as roxygen).
Thanks in advance
You should not write the manual pages yourself. You should use roxygen code to write the manual elements in your function R files, then use devtools::document() to generate the manual pages. See here for examples: https://keithmcnulty.github.io/r_package_training/index.html#1
I am trying to use the zdepth R function from the package wilcox_R available at github. As suggested, I used the usual command lines:
library("devtools"); install_github("musto101/wilcox_R")
However, I received the following error:
Any way out of this would be of great help.
There are problems with the package metadata that are preventing it from building, probably because the author hasn't finished developing the package yet.
Probably the easiest way to use the zdepth function is to download the repository source code. Open the repository in github (https://github.com/musto101/wilcox_R) then click Clone or Download and Download Zip.
Unzip the archive and the zdepth function looks like it's in R/zdepth.R. Copy this file to your own project then load the function with source(), e.g.: source("R/zdepth.R").
This is not the 'best' way to use this function, particularly if you want to use other functions in the package, but short of fixing the metadata yourself it's the most straightforward.
I have created a package in R. It is all fully documented and written according to R package guidelines. I have used devtools to generate documentation.
document("/home/rstudio/EndoMineR/")
However when I try to use ?EndoMineR I get the error:
No documentation for ‘EndoMineR’ in specified packages and libraries:
you could try ‘??EndoMineR’
How can I create the help files for my package? What am I likely to be missing?
As additional information, when I click the package name in R studio I get the help files but not if I try ?EndoMineR. Also the .Rd files in the man directory (which I think is what devtools::document() generates) seem to be updating just fine. I assume the ?EndoMiner accesses the man files so I'm not sure why this folder is not accessible (it is top level)
I made an R package for personal use, but the way I load it is by individual files. Such as:
source("../compr/R/compr.R")
source("../compr/R/error_df.R")
source("../compr/R/rmse.R")
I would like to load the entire package, which is called compr, as I would other libraries.
If you are using RStudio, I would suggest creating a project and setting it to your compr directory. After that you will be able to use devtools::load_all() to load your package directly.
If you don't want to do this, or you don't use RStudio devtools::load_all('path/to/compr') will also work.
P.S. compr directory needs to be the root of the package i.e. the place where your DESCRIPTION file is.
I am planing to do all my R scripts in the same package in order to move it easily between my friends.
What I have done is created an R packages using R studio and the following files have been automatically generated:
projectName.Rproj
DESCRIPTION
man
NAMESPACE
R
Read-and-delete-me
I created a new R script and I save it in R folder. Now I want to add a new R script that uses functions that have been defined in the first script.
I created this new script and I tried to use on of the functions that are located in the other script. I got error that the function is not defined.
What I tried to solve the problem
I used the source command in the beginning of the new script like this:
source('something.R')
I got error message that something.R doesn't exist.
What is the solution please to include functions that exist in a different scripts ** but in the same packages**?
NoteI don't want to use relative paths because I want the package to be as portable as possible
Thanks a lot
You appear to misunderstand how package works: by having a file with a function in the R/ directory, it is already visible to other code in the package.
If you want to make it available to other packages, you can control this via the NAMESPACE file. All this is well-documented in Writing R Extensions which comes with your copy of R, and a number of additional books and tutorials you could peruse.