Skip to content

Namespace clash with NLP package #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zippeurfou opened this issue Jun 23, 2015 · 18 comments
Closed

Namespace clash with NLP package #233

zippeurfou opened this issue Jun 23, 2015 · 18 comments

Comments

@zippeurfou
Copy link

Hi,
I am running mac os x

> library(plotly)
> packageVersion("plotly")
[1] ‘0.6.3’
> mds <- data.frame(State=c("Alabama", "Alabama", "Alabama", "Alabama",
+                           "Arizona", "Arizona"),
+                   City=c("HUNTSVILLE", "MOBILE", "BIRMINGHAM", "MONTGOMERY",
+                          "TUCSON", "PEORIA"),
+                   coord.1=c(1.561284, 6.088862, 9.978292, 15.454877,
+                             23.225289, -7.283954),
+                   coord.2=c(0.2228790, 0.8343259, -3.6507234, -4.8520206,
+                             -0.4438650, 9.1252792),
+                   Division=c("East South Central", "East South Central",
+                              "East South Central", "East South Central",
+                              "Mountain", "Mountain"))
> gg <- ggplot(mds) +
+     geom_text(aes(x=coord.1, y=coord.2, label=City, colour=Division))
> 
> L <- gg2list(gg)
Error in gg2list(gg) : object 'nann' not found

Is this the normal behavior?

@13bzhang
Copy link
Contributor

Thanks for reporting this issue. I have been able to replicate the same error on my Linux. I will try to debug today.

@13bzhang
Copy link
Contributor

@zippeurfou Hi! I tried your code on my Mac today and everything works. Are you still having the same problem?

Here's the Plotly plot I made:
https://plot.ly/~13bzhang/963/coord2-vs-coord1/

233_color

And here's the list output from gg2list:

$data
$data[[1]]
$data[[1]]$x
[1]  1.561284  6.088862  9.978292 15.454877

$data[[1]]$y
[1]  0.2228790  0.8343259 -3.6507234 -4.8520206

$data[[1]]$text
[1] HUNTSVILLE MOBILE     BIRMINGHAM MONTGOMERY
Levels: BIRMINGHAM HUNTSVILLE MOBILE MONTGOMERY PEORIA TUCSON

$data[[1]]$type
[1] "scatter"

$data[[1]]$mode
[1] "text"

$data[[1]]$textfont
$data[[1]]$textfont$color
[1] "#F8766D"


$data[[1]]$name
[1] "East South Central"

$data[[1]]$xaxis
[1] "x1"

$data[[1]]$yaxis
[1] "y1"

$data[[1]]$showlegend
[1] TRUE


$data[[2]]
$data[[2]]$x
[1] 23.225289 -7.283954

$data[[2]]$y
[1] -0.443865  9.125279

$data[[2]]$text
[1] TUCSON PEORIA
Levels: BIRMINGHAM HUNTSVILLE MOBILE MONTGOMERY PEORIA TUCSON

$data[[2]]$type
[1] "scatter"

$data[[2]]$mode
[1] "text"

$data[[2]]$textfont
$data[[2]]$textfont$color
[1] "#00BFC4"


$data[[2]]$name
[1] "Mountain"

$data[[2]]$xaxis
[1] "x1"

$data[[2]]$yaxis
[1] "y1"

$data[[2]]$showlegend
[1] TRUE



$layout
$layout$xaxis
$layout$xaxis$tickcolor
[1] "rgb(127,127,127)"

$layout$xaxis$gridcolor
[1] "rgb(255,255,255)"

$layout$xaxis$showgrid
[1] TRUE

$layout$xaxis$ticks
[1] "outside"

$layout$xaxis$showticklabels
[1] TRUE

$layout$xaxis$type
[1] "linear"

$layout$xaxis$title
[1] "coord.1"

$layout$xaxis$zeroline
[1] FALSE

$layout$xaxis$showline
[1] FALSE


$layout$yaxis
$layout$yaxis$tickcolor
[1] "rgb(127,127,127)"

$layout$yaxis$gridcolor
[1] "rgb(255,255,255)"

$layout$yaxis$showgrid
[1] TRUE

$layout$yaxis$ticks
[1] "outside"

$layout$yaxis$showticklabels
[1] TRUE

$layout$yaxis$type
[1] "linear"

$layout$yaxis$title
[1] "coord.2"

$layout$yaxis$zeroline
[1] FALSE

$layout$yaxis$showline
[1] FALSE


$layout$plot_bgcolor
[1] "rgb(229,229,229)"

$layout$margin
$layout$margin$r
[1] 10


$layout$legend
$layout$legend$bordercolor
[1] "transparent"

$layout$legend$x
[1] 1.05

$layout$legend$y
[1] 0.5

$layout$legend$xanchor
[1] "center"

$layout$legend$yanchor
[1] "top"

$layout$legend$font
$layout$legend$font$family
[1] ""


$layout$legend$bgcolor
[1] "rgb(255,255,255)"


$layout$showlegend
[1] TRUE

$layout$annotations
$layout$annotations[[1]]
$layout$annotations[[1]]$text
[1] "<b>Division</b>"

$layout$annotations[[1]]$x
[1] 1.05

$layout$annotations[[1]]$y
[1] 0.52

$layout$annotations[[1]]$showarrow
[1] FALSE

$layout$annotations[[1]]$xref
[1] "paper"

$layout$annotations[[1]]$yref
[1] "paper"

$layout$annotations[[1]]$xanchor
[1] "center"

$layout$annotations[[1]]$textangle
[1] 0



$layout$titlefont
$layout$titlefont$family
[1] ""


$layout$paper_bgcolor
[1] "rgb(255,255,255)"

@zippeurfou
Copy link
Author

This is weird. I am still having the same issue after updating with

devtools::install_github("ropensci/plotly")

On Thu, Jun 25, 2015 at 2:28 PM, Baobao Zhang [email protected]
wrote:

@zippeurfou https://github.com/zippeurfou Hi! I tried your code on my
Mac today and everything works. Are you still having the same problem?

Here's the Plotly plot I made:
https://plot.ly/~13bzhang/963/coord2-vs-coord1/

[image: 233_color]
https://cloud.githubusercontent.com/assets/6131842/8362384/763f6844-1b46-11e5-80ad-f086eaf79d09.png

And here's the list output from gg2list:

$data$data[[1]]$data[[1]]$x
[1] 1.561284 6.088862 9.978292 15.454877
$data[[1]]$y
[1] 0.2228790 0.8343259 -3.6507234 -4.8520206
$data[[1]]$text
[1] HUNTSVILLE MOBILE BIRMINGHAM MONTGOMERYLevels: BIRMINGHAM HUNTSVILLE MOBILE MONTGOMERY PEORIA TUCSON
$data[[1]]$type
[1] "scatter"
$data[[1]]$mode
[1] "text"
$data[[1]]$textfont$data[[1]]$textfont$color
[1] "#F8766D"

$data[[1]]$name
[1] "East South Central"
$data[[1]]$xaxis
[1] "x1"
$data[[1]]$yaxis
[1] "y1"
$data[[1]]$showlegend
[1] TRUE

$data[[2]]$data[[2]]$x
[1] 23.225289 -7.283954
$data[[2]]$y
[1] -0.443865 9.125279
$data[[2]]$text
[1] TUCSON PEORIALevels: BIRMINGHAM HUNTSVILLE MOBILE MONTGOMERY PEORIA TUCSON
$data[[2]]$type
[1] "scatter"
$data[[2]]$mode
[1] "text"
$data[[2]]$textfont$data[[2]]$textfont$color
[1] "#00BFC4"

$data[[2]]$name
[1] "Mountain"
$data[[2]]$xaxis
[1] "x1"
$data[[2]]$yaxis
[1] "y1"
$data[[2]]$showlegend
[1] TRUE

$layout$layout$xaxis$layout$xaxis$tickcolor
[1] "rgb(127,127,127)"
$layout$xaxis$gridcolor
[1] "rgb(255,255,255)"
$layout$xaxis$showgrid
[1] TRUE
$layout$xaxis$ticks
[1] "outside"
$layout$xaxis$showticklabels
[1] TRUE
$layout$xaxis$type
[1] "linear"
$layout$xaxis$title
[1] "coord.1"
$layout$xaxis$zeroline
[1] FALSE
$layout$xaxis$showline
[1] FALSE

$layout$yaxis$layout$yaxis$tickcolor
[1] "rgb(127,127,127)"
$layout$yaxis$gridcolor
[1] "rgb(255,255,255)"
$layout$yaxis$showgrid
[1] TRUE
$layout$yaxis$ticks
[1] "outside"
$layout$yaxis$showticklabels
[1] TRUE
$layout$yaxis$type
[1] "linear"
$layout$yaxis$title
[1] "coord.2"
$layout$yaxis$zeroline
[1] FALSE
$layout$yaxis$showline
[1] FALSE

$layout$plot_bgcolor
[1] "rgb(229,229,229)"
$layout$margin$layout$margin$r
[1] 10

$layout$legend$layout$legend$bordercolor
[1] "transparent"
$layout$legend$x
[1] 1.05
$layout$legend$y
[1] 0.5
$layout$legend$xanchor
[1] "center"
$layout$legend$yanchor
[1] "top"
$layout$legend$font$layout$legend$font$family
[1] ""

$layout$legend$bgcolor
[1] "rgb(255,255,255)"

$layout$showlegend
[1] TRUE
$layout$annotations$layout$annotations[[1]]$layout$annotations[[1]]$text
[1] "Division"
$layout$annotations[[1]]$x
[1] 1.05
$layout$annotations[[1]]$y
[1] 0.52
$layout$annotations[[1]]$showarrow
[1] FALSE
$layout$annotations[[1]]$xref
[1] "paper"
$layout$annotations[[1]]$yref
[1] "paper"
$layout$annotations[[1]]$xanchor
[1] "center"
$layout$annotations[[1]]$textangle
[1] 0

$layout$titlefont$layout$titlefont$family
[1] ""

$layout$paper_bgcolor
[1] "rgb(255,255,255)"


Reply to this email directly or view it on GitHub
#233 (comment).

Marc Ferradou : www.marc.ferradou.fr [image: View my
profile on LinkedIn]View my profile
http://www.linkedin.com/in/marcferradou

@13bzhang
Copy link
Contributor

@zippeurfou I am sorry to hear that. You could try installing @cpsievert 's experimental branch:

devtools::install_github("ropensci/plotly@carson-dsl")

It worked for me. Let me know how it goes.

@zippeurfou
Copy link
Author

Still not 😢

> devtools::install_github("ropensci/plotly@carson-dsl")
Downloading github repo ropensci/plotly@carson-dsl
Installing plotly
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore CMD INSTALL  \
  '/private/var/folders/6f/byx9_ytd6694gl1m20qvxtjw0000gn/T/RtmpxyOhyO/devtoolsf39a1e57536b/ropensci-plotly-66f8c62'  \
  --library='/Library/Frameworks/R.framework/Versions/3.1/Resources/library' --install-tests 

* installing *source* package ‘plotly’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (plotly)
Reloading installed plotly

Howdy, marc.tse!
Sweet, you have an API key already! 
Start making plots with ggplotly() or plot_ly().

Attaching package: ‘plotly’

The following object is masked from ‘package:graphics’:

    layout

> mds <- data.frame(State=c("Alabama", "Alabama", "Alabama", "Alabama",
+                           "Arizona", "Arizona"),
+                   City=c("HUNTSVILLE", "MOBILE", "BIRMINGHAM", "MONTGOMERY",
+                          "TUCSON", "PEORIA"),
+                   coord.1=c(1.561284, 6.088862, 9.978292, 15.454877,
+                             23.225289, -7.283954),
+                   coord.2=c(0.2228790, 0.8343259, -3.6507234, -4.8520206,
+                             -0.4438650, 9.1252792),
+                   Division=c("East South Central", "East South Central",
+                              "East South Central", "East South Central",
+                              "Mountain", "Mountain"))
> gg <- ggplot(mds) +
+     geom_text(aes(x=coord.1, y=coord.2, label=City, colour=Division))
> 
> L <- gg2list(gg)
Error in gg2list(gg) : object 'nann' not found

@cpsievert
Copy link
Collaborator

Hi @zippeurfou, could you include the output of sessionInfo()?

@zippeurfou
Copy link
Author

> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.2 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] plotly_1.0.0       RJSONIO_1.3-0      RCurl_1.95-4.6     bitops_1.0-6       knitr_1.10.5       gridExtra_0.9.1    RColorBrewer_1.1-2 tm_0.6             NLP_0.1-7         
[10] slam_0.1-32        SnowballC_0.5.1    dplyr_0.4.2        ggplot2_1.0.1      DBI_0.3.1         

loaded via a namespace (and not attached):
 [1] assertthat_0.1    colorspace_1.2-6  curl_0.9          devtools_1.8.0    digest_0.6.8      git2r_0.10.1      gtable_0.1.2      highr_0.5         htmltools_0.2.6   httr_0.6.1       
[11] jsonlite_0.9.16   labeling_0.3      lazyeval_0.1.10   magrittr_1.5      MASS_7.3-41       memoise_0.2.1     munsell_0.4.2     parallel_3.1.3    plyr_1.8.3        proto_0.3-10     
[21] R6_2.0.1          Rcpp_0.11.6       reshape2_1.4.1    rmarkdown_0.7     RMySQL_0.10.3     rsconnect_0.4.1.2 rstudioapi_0.3.1  rversions_1.0.1   scales_0.2.5      stringi_0.5-2    
[31] stringr_1.0.0     tools_3.1.3       xml2_0.1.1        yaml_2.1.13      

@cpsievert
Copy link
Collaborator

Huh, strange, could you try running this example in a clean R session? That is, restart R (or start a new session) and run the example. If that doesn't work, let us know and report the sessionInfo() again.

@zippeurfou
Copy link
Author

It worked. It is still weird that it did not work before:

Restarting R session...

Loading required package: RMySQL
Loading required package: DBI
> devtools::install_github("ropensci/plotly@carson-dsl")
Downloading github repo ropensci/plotly@carson-dsl
Installing plotly
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore CMD INSTALL  \
  '/private/var/folders/6f/byx9_ytd6694gl1m20qvxtjw0000gn/T/RtmpIpcuA2/devtools11ec27f375e5/ropensci-plotly-66f8c62'  \
  --library='/Library/Frameworks/R.framework/Versions/3.1/Resources/library' --install-tests 

* installing *source* package ‘plotly’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (plotly)
> library(plotly)
Loading required package: ggplot2

Howdy, marc.tse!
Sweet, you have an API key already! 
Start making plots with ggplotly() or plot_ly().

Attaching package: ‘plotly’

The following object is masked from ‘package:graphics’:

    layout

> mds <- data.frame(State=c("Alabama", "Alabama", "Alabama", "Alabama",
+                           "Arizona", "Arizona"),
+                   City=c("HUNTSVILLE", "MOBILE", "BIRMINGHAM", "MONTGOMERY",
+                          "TUCSON", "PEORIA"),
+                   coord.1=c(1.561284, 6.088862, 9.978292, 15.454877,
+                             23.225289, -7.283954),
+                   coord.2=c(0.2228790, 0.8343259, -3.6507234, -4.8520206,
+                             -0.4438650, 9.1252792),
+                   Division=c("East South Central", "East South Central",
+                              "East South Central", "East South Central",
+                              "Mountain", "Mountain"))
> gg <- ggplot(mds) +
+     geom_text(aes(x=coord.1, y=coord.2, label=City, colour=Division))
> 
> L <- gg2list(gg)
> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.2 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_1.0.0  ggplot2_1.0.1 RMySQL_0.10.3 DBI_0.3.1    

loaded via a namespace (and not attached):
 [1] assertthat_0.1   bitops_1.0-6     colorspace_1.2-6 curl_0.9         devtools_1.8.0   digest_0.6.8     dplyr_0.4.2      git2r_0.10.1     grid_3.1.3       gtable_0.1.2     httr_0.6.1      
[12] jsonlite_0.9.16  labeling_0.3     magrittr_1.5     MASS_7.3-41      memoise_0.2.1    munsell_0.4.2    parallel_3.1.3   plyr_1.8.3       proto_0.3-10     R6_2.0.1         Rcpp_0.11.6     
[23] RCurl_1.95-4.6   reshape2_1.4.1   rstudioapi_0.3.1 rversions_1.0.1  scales_0.2.5     stringi_0.5-2    stringr_1.0.0    tools_3.1.3      xml2_0.1.1      
> 

@cpsievert
Copy link
Collaborator

Thanks, glad to know that fixed it.

The problem is caused by loading the NLP package, which changes the behavior of this line. Using exists() in this way is poor practice and should be fixed (feel free to start a PR if you like @13bzhang)

> library(plotly)
Loading required package: ggplot2

Howdy, test_bot!
Sweet, you have an API key already! 
Start making plots with ggplotly() or plot_ly().

Attaching package:plotlyThe following object is masked frompackage:graphics:

    layout

> mds <- data.frame(State=c("Alabama", "Alabama", "Alabama", "Alabama",
+                           "Arizona", "Arizona"),
+                   City=c("HUNTSVILLE", "MOBILE", "BIRMINGHAM", "MONTGOMERY",
+                          "TUCSON", "PEORIA"),
+                   coord.1=c(1.561284, 6.088862, 9.978292, 15.454877,
+                             23.225289, -7.283954),
+                   coord.2=c(0.2228790, 0.8343259, -3.6507234, -4.8520206,
+                             -0.4438650, 9.1252792),
+                   Division=c("East South Central", "East South Central",
+                              "East South Central", "East South Central",
+                              "Mountain", "Mountain"))
> gg <- ggplot(mds) +
+     geom_text(aes(x=coord.1, y=coord.2, label=City, colour=Division))
> 
> L <- gg2list(gg)
> library(NLP)

Attaching package:NLPThe following object is masked frompackage:ggplot2:

    annotate

> L <- gg2list(gg)
Error in gg2list(gg) : object 'nann' not found

@cpsievert cpsievert changed the title test-ggplot-text.R test colour not working on my computer Namespace clash with NLP package Jun 25, 2015
@13bzhang
Copy link
Contributor

I'll fix it.

@zippeurfou
Copy link
Author

@13bzhang @cpsievert this error is now happening again.
On the fix-ggplot branch the NLP package make it bug

@cpsievert cpsievert reopened this Dec 9, 2015
@cpsievert
Copy link
Collaborator

Fixed in 3d9a6b7

@giocomai
Copy link

I still got this error. If I detach the NLP package, everything works fine.

@xuxoramos
Copy link

Any update on this? I'm not loading NLP, but another package that depends on it and it is messing with my plots.

@ngfrey
Copy link

ngfrey commented May 9, 2016

I'm also still having this problem. I think the only way to deal with this is figure out what other packages could cause problems, and either split your analysis into sections that use non-plotly compatible packages, do your analysis, unload those packages, then load plotly and ggplot and graph.

@cpsievert
Copy link
Collaborator

This shouldn't be a problem anymore. Are you using the latest version of plotly?

@ngfrey
Copy link

ngfrey commented May 11, 2016

Hey guys,
I sorta solved the problem...Restarting R didn’t help, some package was still causing problems. However, using the code pasted below to remove packages and then just loading the ggplot and plotyly libraries gave me a quasi solution. I put screen shots in showing the difference between ggplot and plotly’s output. That said, I was able to get plotly output after stripping all loaded packages, so I’ll count that as a little victory in and of itself. However, you’ll see some problems when I go from ggplot to plotly regarding the actual layout of my visualization. I think Plotly has opportunity to improve regarding the ability to honor legend placements, axis labels, title settings, etc. from ggplot.

Here’s the code to unload the packages that worked for me:
From: http://stackoverflow.com/questions/7505547/detach-all-packages-while-working-in-r http://stackoverflow.com/questions/7505547/detach-all-packages-while-working-in-r
Specifically:

sess.pkgs <- function (package = NULL)
{ z <- list()
if (is.null(package)) {
package <- grep("^package:", search(), value = TRUE)
keep <- sapply(package, function(x) x == "package:base" ||
!is.null(attr(as.environment(x), "path")))
package <- sub("^package:", "", package[keep])
}
pkgDesc <- lapply(package, packageDescription)
if (length(package) == 0)
stop("no valid packages were specified")
basePkgs <- sapply(pkgDesc, function(x) !is.null(x$Priority) &&
x$Priority == "base")
z$basePkgs <- package[basePkgs]
if (any(!basePkgs)) {
z$otherPkgs <- package[!basePkgs]
}
z
}

lapply(paste("package:",sess.pkgs()$otherPkgs, sep=""), detach,
character.only = TRUE, unload = TRUE)

Output of my ggplot for my data:

Important to note:

  1. red is always under the blue within each stack, if both failures and acceptable calculation times exist on the same date, this came from ordering the dataset with respect to date plus a given factor var (“Over25”)
    1. legend placement is on bottom, I want this because horizontal real estate is at a premium whenever plotting time series observations
    2. Title fits on output
    3. x-axis labels are initialized close enough to my first observation to make the time scale more easily perceivable

Plotly output (screenshot):

As you can see, not all settings were transferred. This may be because I am significantly less experienced with plotly than ggplot. My apologies for that. At least the alpha settings seem to be spot on.

Anyways, thank you for getting back to me. I think there are still namespace collisions, but I currently do not know which package is causing the problem. I’m sure I’ll figure that out as soon as I start loading each package I need individually, then test to see if I can still make the plot. Once I find the offending package, I’ll get back to ya'll. It seems package parsimony is the best practice thus far.

And just in case you’re interested, I attached the code and data used to build the graphs:

Hope this helps. Again, thank you for getting back to me.

Best,
NF

On May 9, 2016, at 6:15 PM, Carson [email protected] wrote:

This shouldn't be a problem anymore. Are you using the latest version of plotly?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub #233 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants