agstudy's answer describes how to reference a file in an installed package without having to know where the package was installed. The other part of the problem is getting the image file into the installed package.
From the "Package subdirectories" second of Writing R Extensions, the section of interest is about the inst
subdirectory:
The contents of the
inst
subdirectory will be copied recursively to the installation directory. Subdirectories ofinst
should not interfere with those used by R (currently,R
,data
,demo
,exec
,libs
,man
,help
,html
andMeta
, and earlier versions usedlatex
,R-ex
). The copying of theinst
happens aftersrc
is built so itsMakefile
can create files to be installed.
So for a file to appear in the img
directory off the root of the installed package, it must appear in the inst/img
directory of the source. So move rgblegend.png
from img
to inst/img
and then
legend <- readPNG(system.file("img", "rgblegend.png", package="HybRIDS"), TRUE)
should work.