elbamos / largeVis

An implementation of the largeVis algorithm for visualizing large, high-dimensional datasets, for R
340 stars 62 forks source link

largeVis gives errors if the script is launched by Rscript #39

Closed ziyuang closed 7 years ago

ziyuang commented 7 years ago

Environment: OS: Ubuntu 14.04 R: 3.3.2

# test_iris.r
library(largeVis)
data <- iris[,1:4]
data_triplet <- matrix(nrow=dim(data)[1]*dim(data)[2],ncol=3)
triplet_idx <- 1
for (i in 1:dim(data)[1]) {
  for (j in 1:dim(data)[2]) {
    data_triplet[triplet_idx, 1] <- i
    data_triplet[triplet_idx, 2] <- j
    data_triplet[triplet_idx, 3] <- data[i, j]
    triplet_idx <- triplet_idx + 1 
  }
}

sparse_data <- sparseMatrix(i=data_triplet[,1], j=data_triplet[,2], x=data_triplet[,3])
largevis_obj <- largeVis(t(sparse_data))
$ Rscript --vanilla test_iris.r                                                                 
Loading required package: Matrix
Error in UseMethod("randomProjectionTreeSearch") : 
  no applicable method for 'randomProjectionTreeSearch' applied to an object of class "dgCMatrix"
Calls: largeVis -> randomProjectionTreeSearch
Execution halted
$ R CMD BATCH test_iris.r  # safe
elbamos commented 7 years ago

Can you try to run the same code from inside R and see what happens? Start with a fresh session.

On Jan 13, 2017, at 9:30 PM, ziyuang notifications@github.com wrote:

Environment: OS: Ubuntu 14.04 R: 3.3.2

test_iris.r

library(largeVis) data <- iris[,1:4] data_triplet <- matrix(nrow=dim(data)[1]*dim(data)[2],ncol=3) triplet_idx <- 1 for (i in 1:dim(data)[1]) { for (j in 1:dim(data)[2]) { data_triplet[triplet_idx, 1] <- i data_triplet[triplet_idx, 2] <- j data_triplet[triplet_idx, 3] <- data[i, j] triplet_idx <- triplet_idx + 1 } }

sparse_data <- sparseMatrix(i=data_triplet[,1], j=data_triplet[,2], x=data_triplet[,3]) largevis_obj <- largeVis(t(sparse_data)) $ Rscript --vanilla test_iris.r
Loading required package: Matrix Error in UseMethod("randomProjectionTreeSearch") : no applicable method for 'randomProjectionTreeSearch' applied to an object of class "dgCMatrix" Calls: largeVis -> randomProjectionTreeSearch Execution halted $ R CMD BATCH test_iris.r # safe

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ziyuang commented 7 years ago

Yes it is OK.

> source('test_iris.r')
Loading required package: Matrix
> dim(t(largevis_obj$coords))
[1] 150   2
ziyuang commented 7 years ago

I think the reason is that Rscript does not load methods by default but R does. See http://stackoverflow.com/q/19680462/688080. Rscript --default-packages=stats,graphics,grDevices,utils,datasets,methods,base --vanilla test_iris.r works normally.

elbamos commented 7 years ago

Ok I'm going to close this. Let me know if the issues aren't resolved and feel free to reopen.