cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
49 stars 20 forks source link

Check for Inf and -Inf in Double columns during loadTableData #224

Closed AlexanderPico closed 3 months ago

AlexanderPico commented 4 months ago

Re: #223, we could add a fix right about here... https://github.com/cytoscape/RCy3/blob/devel/R/Tables.R#L345

Something like this...

data[] <- lapply(data, function(x){
  if (is.numeric(x)) {
    max_java <- .Machine$integer.max
    min_java <- -.Machine$integer.max
    x[is.infinite(x) & x > 0] <- max_java
    x[is.infinite(x) & x < 0] <- min_java
  }
)
AlexanderPico commented 4 months ago

@yihangx We should test this carefully. Can you also devise test cases if/when you get a chance to implement this?

Something like...

nodes <- data.frame(id=c("node 0","node 1","node 2","node 3"),
           double=as.double(c(2.1,-2.3,Inf,-Inf)), # doubles
           score=as.integer(c(20,-10,Inf,-Inf)), # integers
           stringsAsFactors=FALSE)

createNetworkFromDataFrames(nodes)