Installation Failed during intall_github with wilcox_R package - r

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.

Related

URL '/help/library/<package>/r/html/00Index.html' not found when using `devtools::load_all()`

I am using devtools::load_all as a workflow to iteratively make a package. However, I cannot seem to be able to view the package documentation using ? or help(package=package_name) until I install the package. The error I get is:
No documentation for ‘function’ in specified packages and libraries
and
URL '/help/library//r/html/00Index.html'
any suggestions on how to resolve this?
Thanks!
I guess the help(package=package_name) do nothing than open (in case of Windows) this file for you:
C:\Users\YourName\Documents\R\win-library\4.1\package_name\html\00Index.html
devtools::load_all make your latest functions available to you for testing without installing the package (i.e. the html file was not updated, and masked because it was belonged to the old version of your own package). To view your latest documentation (i.e. make a new version html), you can devtools::document() and check your package working directory \man\Functions_name.rd, OR, devtools::install() and help(package=package_name)
Just restarting r session solved my problem.

Troublesome package creating

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

Error when trying to install package from GitHub

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.

Unable to generate help files from R package

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)

Load my own R package

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.

Resources