0

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

Artie Ladie
  • 521
  • 4
  • 14

1 Answers1

2

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")
Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • 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. Please see repository, "ArtieLadie/RanglaPunjab" – Artie Ladie May 22 '18 at 18:13
  • When I run `ShowPalettePhoto("Teej")` Error is `Error in readJPEG(x, native = TRUE) : unable to open ./Photos/teej.jpg' `Other commands run without error. – Artie Ladie May 22 '18 at 18:29
  • @ArtieLadie You probably want to install the pictures along with the package. See updated answer. – Ralf Stubner May 22 '18 at 18:37
  • I loaded the library and tried `system.file("pics", "teej.jpg", package = "RanglaPunjab")` (system.files is non-existant). Output is `[1] ""` – Artie Ladie May 22 '18 at 18:50
  • @ArtieLadie Typo in my answer: it should reed `system.file` without the plural s. – Ralf Stubner May 22 '18 at 18:55
  • Still having problem, HELP. I identified the system directory, i.e. C:\Users\\Documents\R\win-library\3.5\, but where would I place photos so they end up installed with package, i.e. automatically appearing in system directory? I tried placing in R directory, but still no luck :-( – Artie Ladie May 22 '18 at 19:25
  • @ArtieLadie You don’t have to do this manually. The `inst` folder is at the same level as the (source) R folder. The content of this folders copied verbatim to the installation folder. – Ralf Stubner May 22 '18 at 19:40
  • Well, since `inst` folder wasn't created, let me create and see what happens – Artie Ladie May 22 '18 at 19:56
  • Your answer pointed me in the correct direction. Still tinkering with code. Thank you :-) – Artie Ladie May 23 '18 at 01:28
  • I created separate question. Kindly answer if possible, https://stackoverflow.com/questions/50490007/r-package-unable-to-access-contents-from-inst-folder – Artie Ladie May 23 '18 at 13:44