clauswilke / colorblindr

An R package to simulate colorblindness on R figures.
MIT License
306 stars 29 forks source link

cvd_grid() error #2

Closed isteves closed 7 years ago

isteves commented 7 years ago

Hi Claus, When I try running cvd_grid(), I get the following error: "Error in desaturate(c, severity) : unused argument (severity)"

In the attached screenshot, I did the following: 1) I uninstalled colorspace. 2) I reinstalled colorspace using the code provided in the README (https://github.com/clauswilke/colorblindr/blob/master/README.md). 3) I also ran the installation code for cowplot and colorblindr to show that both are installed and up to date. 4) I then proceeded with the example in the README, which works until I try the cvd_grid function.

Since I was running R v. 3.3.1, I decided to update R to the latest version. I then reinstalled the tidyverse and devtools packages, and then ran the code in the README. However, I still get the same error.

Let me know what further information I can provide to solve this issue. (Still very new at this!)

Thanks, Irene

colorblindr
isteves commented 7 years ago

I tried uninstalling and reinstalling colorspace again, and I get a slightly different warning: "Warning in install.packages : cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES.rds': HTTP status was '404 Not Found'"

image

clauswilke commented 7 years ago

Strange, it still looks like you're using an old colorspace package. Could you show me the output of sessionInfo()?

And also, does this work as it does for me?

> desaturate("red", 0.5)
[1] "#D05959"
clairemcwhite commented 7 years ago

Hi Irene,

Try also doing remove.packages("colorspace") or clicking the (x) from the Packages tab of Rstudio. The devtools uninstall doesn't look like it's meant to be used with packages from repositories.

isteves commented 7 years ago

In response to your first message:

email1
isteves commented 7 years ago

The error changed when I reinstalled it, so I guess it's some kind of progress.

email2
clauswilke commented 7 years ago

You're somehow stuck with an outdated or inconsistent colorspace package. I'm honestly not sure what to tell you, because the problem is with the colorspace package, not with my code. The development version of colorspace added the option to do partial desaturation, as in desaturate("red", 0.5), and for some reason that's not working for you.

Actually, I just removed and reinstalled colorspace on my system:

> remove.packages("colorspace")
Removing package from ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library’
(as ‘lib’ is unspecified)

Restarting R session...

> colorspace::desaturate("red", 0.5)
Error in loadNamespace(name) : there is no package called ‘colorspace’
> install.packages("colorspace", repos = "http://R-Forge.R-project.org")
Warning in install.packages :
  unable to access index for repository http://R-Forge.R-project.org/bin/macosx/el-capitan/contrib/3.4:
  cannot open URL 'http://R-Forge.R-project.org/bin/macosx/el-capitan/contrib/3.4/PACKAGES'
Package which is only available in source form, and may need compilation of C/C++/Fortran:
  ‘colorspace’
Do you want to attempt to install these from sources?
y/n: y
installing the source package ‘colorspace’

trying URL 'http://R-Forge.R-project.org/src/contrib/colorspace_1.3-3.tar.gz'
Content type 'application/x-gzip' length 557896 bytes (544 KB)
==================================================
downloaded 544 KB

* installing *source* package ‘colorspace’ ...
** libs
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c colorspace.c -o colorspace.o
colorspace.c:589:13: warning: unused function 'CheckGamma' [-Wunused-function]
static void CheckGamma(SEXP gamma, double *gammaval)
            ^
1 warning generated.
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c init.c -o init.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o colorspace.so colorspace.o init.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/colorspace/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (colorspace)

The downloaded source packages are in
    ‘/private/var/folders/6z/ct5bjltn3_75xslq8gm5kmhc0000gn/T/Rtmpd6i0hU/downloaded_packages’
> colorspace::desaturate("red", 0.5)
[1] "#D05959"

You may notice one difference: R is installing a source package and is compiling C code. That does not happen for you, instead you get a binary install, likely because you're on Windows. The binary install probably doesn't contain the code change that is necessary to get colorblindr working, likely because the latest change in the colorspace code was made without change in the version number.

Take-home message from all of this: Contact the colorspace maintainer and tell him that you'd like to install a version of colorspace that can do partial desaturation (as in colorspace::desaturate("red", 0.5)) but even when you install from R Forge that doesn't work.

clairemcwhite commented 7 years ago

Confirmed that on Windows, the colorspace from R-Forge gives the old desaturate function.

install.packages("colorspace", repos = "http://R-Forge.R-project.org") colorspace::desaturate function (col) { if (is.character(col) && (all(substr(col, 1L, 1L) == "#") & all(nchar(col) %in% c(7L, 9L)))) { alpha <- substr(col, 8L, 9L) col <- substr(col, 1L, 7L) col <- hex2RGB(col) } else { col <- col2rgb(col, alpha = TRUE) alpha <- format(as.hexmode(col[4L, ]), width = 2L, upper.case = TRUE) alpha[alpha == "FF"] <- "" col <- RGB(t(col[1L:3L, ])/255) } col <- as(col, "polarLUV") col@coords[, 2L] <- 0 col@coords[col@coords[, 1L] <= 0 | col@coords[, 1L] >= 100, 2L:3L] <- 0 col <- hex(col) col <- paste(col, alpha, sep = "") return(col) }

My deleted post wasn't right. Claus' version of colorspace fixes desaturate but currently isn't working with full colorblindr. It should be quick fix though, we'll get back to you.

clairemcwhite commented 7 years ago

I fixed the desaturate function in Claus' version of colorspace to match the R-forge colorspace function. This is what was causing the issue with 'unused argument'. If you get the 'scale_list' error again, close Rstudio completely and start a new session.

I've just checked on a Windows computer. The following combo works for me

> devtools::install_github("wilkelab/cowplot")
> devtools::install_github("clauswilke/colorspace")
> devtools::install_github("clauswilke/colorblindr")
>library(colorblindr)
> p <- ggplot(iris, aes(Sepal.Width, fill=Species)) +
    geom_density(alpha = 0.7)
> cvd_grid(p)

To check that colorspace is updated, desaturate should now have the arguments col and amount instead of just col.

> library(colorspace)
> desaturate
function (col, amount = 1) 
{
    if (is.character(col) && (all(substr(col, 1L, 1L) == "#") & 
        all(nchar(col) %in% c(7L, 9L)))) {
        alpha <- substr(col, 8L, 9L)
        col <- substr(col, 1L, 7L)
        col <- hex2RGB(col)
    }
    else {
        col <- col2rgb(col, alpha = TRUE)
        alpha <- format(as.hexmode(col[4L, ]), width = 2L, upper.case = TRUE)
        alpha[alpha == "FF"] <- ""
        col <- sRGB(t(col[1L:3L, ])/255)
    }
    col <- as(col, "polarLUV")
    col@coords[, 2L] <- (1 - amount) * col@coords[, 2L]
    col@coords[col@coords[, 1L] <= 0 | col@coords[, 1L] >= 100, 
        2L:3L] <- 0
    col <- hex(col)
    col <- paste(col, alpha, sep = "")
    return(col)
}
<environment: namespace:colorspace>

@isteves ,thanks so much for noticing this issue!

isteves commented 7 years ago

Thanks for working out the issue! It seems to be fine now. Just one more small note: to reinstall the colorblindr package, I had to change the directory from "wilkelab" to "clauswilke." (It gave me a "Not Found (404)" error otherwise).

So this works: devtools::install_github("clauswilke/colorblindr")

clauswilke commented 7 years ago

Yes, correct, colorblindr is under clauswilke, not under wilkelab.