I have a manually created color palette which my package is using. I have included my .rds
color palette file into my package folder and I refer to it within my functions by load(paste0(getwd(),'/my_palette.rds'))
. However I find it very unpractical for example if I want to share my package, and someone what to change his working directory - then the reference won't work. I'm looking for a solution which would build this color palette within R automatically while installing package so that I don't need to have exact file in package folder to which I have to refer. Is this possible ?
EDIT
I created data/ folder in my package folder using commands below :
x<-load(paste0(getwd(),'/my_palette.rds'))
usethis::usedata(x)
Then I clicked on this .rda
in data/ folder to load this into my working directory. However I don't know how should I refer to it. load('x')
doesn't work.
EDIT vol 2
I will describe full algorithm of adding my_palette.rds
to my package which I'm applying :
- Create manual color palette
- Refer to it by command
x<-load(dir/my_palette.rds)
- Then I'm using command
usethis::use_data(x)
(then data/ folder is created with .rda file within it) - After that I'm using
ggplot2
function withscale_fill_manual(my_package::x)
. The warning I get is :Error: Unknown colour name: my_palette
EDIT vol 3
I want to describe process of creating color palette so that we can see where is the basis of the error. So the main difference between what you did and what I did is that you created colour palette as a vector of color to future reference.
(This is very important, your colour palette is stored in a vector type). what I did is to create functions which create a colour palette and after that I saved it into .rds
file. And I believe that it might be the main difference that my colour palette is stored within file. Do you think that it's significant difference ? Or it can be omitted somehow ?