# install.packages(c("httr", "jsonlite"))
colorgorical <- function(n = 10) {
post_body <- jsonlite::toJSON(
auto_unbox = TRUE,
list(
'paletteSize' = n,
'weights' = list(
'ciede2000' = 0,
'nameDifference' = 0,
'nameUniqueness' = 0,
'pairPreference' = 0
),
'hueFilters' = list(),
'lightnessRange' = c("25", "85"),
'startPalette' = list()
)
)
retval <- httr::POST(
url = 'http://vrl.cs.brown.edu/color/makePalette',
body = post_body
)
retval <- httr::content(retval)
lab2hex <- function(Lab) rgb(convertColor(Lab, from = "Lab", to = "sRGB"))
return(sapply(retval$palette, function(x) {
lab2hex(unlist(x[1:3]))
}))
}
> pal <- colorgorical(21)
> pal
[1] "#09C472" "#6C3918" "#C88106" "#C3A0C7" "#269EB3" "#5EE8EF" "#CE3AF6" "#CDDB9B" "#F84F9C"
[10] "#544793" "#B6D320" "#74158E" "#AE301F" "#115305" "#6E8E3B" "#76F013" "#1D4C5E" "#FE7446"
[19] "#668BFB" "#FBD106" "#B471F2"
Nice function! You could add
httr::
to thecontent()
-call:because you're not loading the libraries, and the namespace-reference is missing here.