Duplicate package documentation in RStudio - r

I've started creating a package through RStudio. When I start a new package (New Project -> New Directory -> R Package) the documentation for the base package is duplicated, with one help page titled 'packagename-package' and the other called 'packagename' (see image below).
Although there are two help pages visible, there is only one .Rd file in the man/ folder ('packagename-package.Rd'). When I edit this .Rd file, the information changes in both the duplicate help pages. Is this a known issue when building packages in RStudio, and is there a way to get rid of one of these duplicates?
Thanks for your help.

Related

Organized R Package Manual Help Pages (Table of Contents) [duplicate]

Some R packages (e.g., ggplot2, dplyr,devtools etc.) have alphabetically entitled sections in their help/documentation and a bar of links to those sections (indicated by red arrows in picture below). Other packages (e.g., RcmdrMisc) don't have.
How can I add these elements to may R package's help?
I use roxygen2 for documentation.
In the Writing R Extensions file (included with every copy of R from CRAN) is a small section regarding the INDEX file:
1.1.4 The INDEX file
The optional file INDEX contains a line for each sufficiently interesting object in the package, giving its name and a description (functions such as print methods not usually called explicitly might not be included). Normally this file is missing and the corresponding information is automatically generated from the documentation sources (using tools::Rdindex()) when installing from source.
When packages have an index file, the HTML code is in the html folder.
The help index page is automatically generated by R when you install a package. But note that the alphabetical index is only generated when there are more than 100 items on the index page. There is currently no way to change that behavior. I found that in the code for installing packages
As #iRTFM and #MrFlick say, you can't affect the index displayed by R. However, if you use the pkgdown package to make a package web page, you have full control over the main index for the help pages. For example, see
https://ggplot2.tidyverse.org/reference/index.html
The description about how that index was specified is given in the help page ?pkgdown::build_reference, which is displayed here:
https://pkgdown.r-lib.org/reference/build_reference.html

How to load self-written package documentation with '?my_package_name'?

I made a package in R called "my_package_name". When I run ?my_package_name or ??_my_package_name, no results are found. I want a help file to be loaded in the same way that ?ggplot2 loads a package help file.
I can run ?my_function_name to obtain the help files for my functions. However, this does not work with my package name, even though the description file is complete. I found that help(package = my_package_name) loads a page that contains the description file and help pages, but I would like load a page with ?my_package_name.
I would say that the easiest way is probably to run the following from the usethis package. It will create the file needed to have your package documentation
usethis::use_package_doc()
I suggest reading the documentation of the function to understand what's going on under the hood.

Created R Package, Unable to Display Photo

Update
Issue resolved
Update, still not working
Tried the following in R file
(1) deleted both library(...) packages
(2) Added #import jpeg before ShowPalettePhoto() and #import tidyverse before RanglaPunjab() so roxygen automatically adds to NAMESPACE.
After running devtools::document(), ran devtools::use_package("jpeg") and devtools::use_package("tidyverse") to automatically add to DESCRIPTION.
Unfortunately, even in testing, I cannot get JPEG photo.
Here is GitHub repository, https://github.com/ArtieLadie/RanglaPunjab
I created R package according to this tutorial
It worked and I was able to execute all commands, including a function to display photo in another directory.
I uploaded to my GitHub account. Anyone can install package in R environment with install_github("ArtieLadie/RanglaPunjab")
I am able to run functions by adding RanglaPunjab:: in front of it, i.e.
RanglaPunjab::PaintPalette("Jutti")
?RanglaPunjab::MergePalette
However, when I try to run ?RanglaPunjab::ShowPalettePhoto("Teej") I get
Error in readJPEG(x, native = TRUE) : could not find function "readJPEG"
Before creating the package I added function to set working directory to file location, but it was creating errors when I ran install("RanglaPunjab"), i.e. "Cannot execute"
Here are the exact commands I had, which I had to delete from code
library(rstudioapi)
current_path <- getActiveDocumentContext()$path
setwd(dirname(current_path ))
Please help
Your dependencies are not handled correctly. Here you explicitly load packages with library(...). That is not how one does that in an R package. You should add your dependencies to the Imports: section of the DESCRIPTION file and use the package::function() syntax when calling the function. c.f. http://r-pkgs.had.co.nz/description.html#dependencies.
In addition, if you want the images to be installed with your package, you should place them for example in inst/pics. You can then get the path to these files with
system.file("pics", <file-name>, package = "RanglaPunjab")

Edit the default PDF manual generated while building R package

I have succsesfully performed the below steps to create my own R package :
created skeleton of the package and pasted .Rd, NAMESPACE and DESCRIPTION files.
executed R CMD check package_name : no errors, it also generated 2 pdf's
One of which contains the output's from .Rd file examples and second is the PDF manual that comprises the documentation itself.
My question is how to make edits to this manual created, such as to change the font size or add an Introductory page to this manual? I read that roxygen / devtools might help but no resource on that was attained. I also went through the Writing R Extensions link that is available but couldn't help me.
Would there be a way using Rd2pdf? but such that even non .Rd files are also included

Including Script Files in an R Extension Package

I'm creating an R package and I need it to include a couple of non R script files which get called by one of my functions. I need these script files to be distributed with the package, naturally. So that leaves me with two questions:
a) In which directory of the package
tree should I place these files? b) Is that location mandatory or just convention?
Do I need to change any other
settings or configurations or will
they just get copied to the
directory mentioned in #1 and then I
can figure out the path using
system.file()?
I've tried to find the answer in the Writing R Extensions document, but it didn't jump out at me. And, of course, I didn't read the whole thing. Am I being too honest here?
I think you want either exec/ at the top-level (even though that is labeled 'still experimental, or subdirectory of inst as everything in inst/ gets copied verbatim into the package.
A quick example from the packages I have expanded in source is gdata which has inst/perl, inst/xls and inst/bin. These you could then call from R itself by computing the path of the installed package using system.file().

Resources