R-program - igraph package error - linux

I have encountered an error message in an R Program (see code\details below) when I tried to use igraph library in my Xubuntu VM. This problem did not happen before . Everything was working just fine.
It started very recently when I was trying to re-set-up R\igraph in another new VM(Xubuntu) of mine.
Can anybody give me any kind of advice regarding how to fix this problem?
Below are the Details -
Error Message -
Attaching package: ‘igraph’
The following objects are masked from ‘package:stats’:
decompose, spectrum
The following object is masked from ‘package:base’:
union
Loading required package: methods
Attaching package: ‘igraph’
The following objects are masked from ‘package:stats’:
decompose, spectrum
The following object is masked from ‘package:base’:
union
How I installed R Base & Igraph -
sudo apt-get -y install r-base
sudo echo "r <- getOption('repos'); r['CRAN'] <- 'http://cran.us.r- project.org'; options(repos = r);" > ~/.Rprofile
sudo Rscript -e "install.packages('ggplot2')"
sudo Rscript -e "install.packages('plyr')"
sudo Rscript -e "install.packages('reshape2')"
sudo Rscript -e "install.packages('igraph')"
sudo Rscript -e "install.packages('doBy')"
sudo Rscript -e "install.packages('stargazer')"
My R - Program
library(igraph)
g <- read.graph("DataForImage.net", format="pajek")
g <- delete.vertices(g,which(degree(g)<1))
jpeg(filename = "Image1.jpg", width = 2000, height = 2000,
units = "px", pointsize = 10, bg = "white",
res = NA)
g <- simplify(g)
l <- layout.fruchterman.reingold(g, dim=2,verbose=TRUE)
l <- layout.norm(l, -1,1, -1,1)
fcs <- fastgreedy.community(simplify(as.undirected(g)))
Q <- round(max(fcs$modularity), 3)
fcs <- community.to.membership(g, fcs$merges, steps=which.max(fcs$modularity)-1 )
plot(g, layout=l,vertex.shape="circle", vertex.size=2, vertex.label=NA, vertex.color="black",
vertex.frame.color="black", edge.width=5,
rescale=FALSE, xlim=range(l[,1]), ylim=range(l[,2]),
main="")
results <- read.table("detailTotals.csv", header=TRUE, sep=",")
jpeg(filename = "Image2.jpg", width = 2000, height = 2000,
units = "px", pointsize = 50, bg = "white",
res = NA)
plot(results$SetLineTotal, results$SetCount, main="Set Analysis",
xlab="Set Lines", ylab="Set Counts", col="black", bg="black", pch=21, cex=1)
grid(nx = 50, ny = 50, col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)

I thought I will share the final solution that seems to work for me.
I digged down a bit and upon some analysis , I found out the below.
The error seems to be with the igraph version - V1.0. The code statement in above R - program
l <- layout.fruchterman.reingold(g, dim=2,verbose=TRUE)
errors out in igraph V1.0.
The R-igraph package is re-written - and thereby some of the functions\network algorithms from older version is replaced\re-coded\modified in newer igraph version - 1.0 onwards.
So I reverted back to an older igraph package (0.7.1) and now I am no more facing the issue. And my R-program seems to work fine.
Below are the commands to revert to an older igraph package 0.7.1
wget http://cran.r-project.org/src/contrib/Archive/igraph/igraph_0.7.1.tar.gz
sudo R CMD INSTALL igraph_0.7.1.tar.gz

Related

spatstat integer overflow error in Kcross and crosspairs

I'm working with spatstat 2.3-4 in R 4.1.0 on a 64bit windows 10 pro machine.
Recently I ran into the integer-overflow error while using Kcross with a large number of points (i.e. the number of combination exceeded .Machine$integer.max). For example:
W <- as.owin(list(xrange = c(688.512, 17879.746) , yrange = c(-27996.842, -7759.813)))
cells1 <- runifpoint(n = 8062, win = W)
cells2 <- runifpoint(n = 1768988, win = W)
cells3 <- superimpose(tumor = cells1 , bcell = cells2)
Kcross(cells3 , r = seq(0,200,by=5) , "tumor" , "bcell" , correction="none") # error
# Error in if (nXY <= 1024) { : missing value where TRUE/FALSE needed
# In addition: Warning message: In nX * nY : NAs produced by integer overflow
8062 * 1768988 > .Machine$integer.max
# [1] TRUE
After a lot of struggling I realized that the error comes from this part of crosspairs:
if (spatstat.options("crosspairs.newcode")) {
nXY <- nX * nY
if (nXY <= 1024) {
nsize <- 1024
}
I could "fix" the error by changing spatstat options: spatstat.options("crosspairs.newcode" = FALSE).
Is this the way to deal with the error?
UPDATE:
As Adrian.Baddeley answered below, there is now a new spatstat.geom version on GitHub (currently: v2.4.-0.029) in which the bug is fixed. The new version works fine without the change of the options.
The bug is fixed in the development version of spatstat.geom available at the GitHub repository
This is a bug in some relatively new code to speed up the underlying function crosspairs.ppp(). Until a new version of spatstat.geom is available you can workaround the problem by setting spatstat.options("crosspairs.newcode" = FALSE) as suggested.

Macro ignores parameter change

Given a FreeCAD model that consists of
Spreadsheet "parameters" with a cell aliased as "radius" and value 50
Icosahedron (from the Pyramids-and-Polyhedrons macro) with Radius=parameters.radius
some facebinders which are unimportant for the purpose of this question,
the python script below opens this model, changes the radius cell in the Spreadsheet to 15, call recompute() on the spreadsheet, invokes touch() on the icosahedron, calls recompute() on the document, and finally tessellates the icosahedron. The z coordinate of the vertex at index 11 in the tessellated mesh happens to be equal to the icosahedron's radius. I was expecting it to change to 15, according to the parameter change. But it remains at its original value 50. What am I doing wrong?
To my understanding the macro's execute method should get invoked during the recomputation of the document.
When I trace Document.recompute() with pudb, I only see it executing Facebinder.execute() but not Icosahedron.execute(). The path it takes from Document.recompute() to Facebinder.execute() method is not visible in pudb; it immediately stops in Facebinder.execute().
FREECADPATH = '/usr/local/lib' # path to your FreeCAD.so or FreeCAD.dll POLYHEDRONS_PATH = '/home/user/.FreeCAD/Mod/Pyramids-and-Polyhedrons'
import sys
sys.path.append(FREECADPATH)
sys.path.append(POLYHEDRONS_PATH)
import FreeCAD
filename = 'icosahedron.FCStd'
newRadius = 15
doc = FreeCAD.open(filename)
sheet = doc.Spreadsheet
sheet.set('radius', str(newRadius))
sheet.recompute()
print('radius = ' + str(sheet.get('radius')))
icosahedron = doc.getObjectsByLabel('Icosahedron')[0]
print('icosahedron.Radius = '+str(icosahedron.Radius))
icosahedron.touch()
doc.recompute()
print('icosahedron.Radius = '+str(icosahedron.Radius))
(vertices, faces) = icosahedron.Shape.tessellate(1)
z11 = vertices[11][2]
print('z11 = ' + str(z11))
FreeCAD.closeDocument(doc.Name)
I figured it out. The reason was Pyramids-and-Polyhedrons not being imported after all.
The first problem was that Pyramids-and-Polyhedrons imports FreeCADGui (in order to install its workbench), which depends on certain native libs that need to be added to LD_LIBRARY_PATH before running the script:
export LD_LIBRARY_PATH=$(echo $(find /usr/local/lib/python3.7/site-packages -maxdepth 2 -mindepth 2 -type f -name *.so* | sed -r 's|/[^/]+$||' | sort -u) | sed -E 's/ /:/g')
Now FreeCADGui could be imported, but it was lacking the required addCommand method that Pyramids-and-Polyhedrons invokes. I found out that FreeCADGui will only be fully initialized after FreeCADGui.showMainWindow() has been called. This requires a display, however, and I want to run the script as part of a headless toolchain in a Docker container. Therefore I added Xvfb to the image. I'm launching it in the background before running the updated script with DISPLAY pointing to Xvfb:
FREECADPATH = '/usr/local/lib' # path to your FreeCAD.so or FreeCAD.dll file
POLYHEDRONS_PATH = '/home/user/.FreeCAD/Mod/Pyramids-and-Polyhedrons'
import sys
sys.path.append(FREECADPATH)
sys.path.append(POLYHEDRONS_PATH)
import FreeCAD
import FreeCADGui
FreeCADGui.showMainWindow()
import polyhedrons
filename = 'icosahedron.FCStd'
newRadius = 15
doc = FreeCAD.open(filename)
sheet = doc.Spreadsheet
sheet.set('radius', str(newRadius))
sheet.recompute()
print('radius = ' + str(sheet.get('radius')))
icosahedron = doc.getObjectsByLabel('Icosahedron')[0]
print('icosahedron.Radius = '+str(icosahedron.Radius))
breakpoint()
icosahedron.touch()
doc.recompute()
print('icosahedron.Radius = '+str(icosahedron.Radius))
(vertices, faces) = icosahedron.Shape.tessellate(1)
z11 = vertices[11][2]
print('z11 = ' + str(z11))
FreeCAD.closeDocument(doc.Name)
Now the output is
...
z11 = 15.0
as expected.

Error when attempting to install Octave IO package

When attempting to install the Octave io package on Windows 7 I receive the following error:
>> pkg install io-2.4.12.tar.gz
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x0, BaseAddress 0x60EA0000, RegionSize 0x190000, State 0x10000
C:\Octave\Octave-4.2.0\bin\perl.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
warning: doc_cache_create: unusable help text found in file 'getxmlattv'
For information about changes from previous versions of the io package, run 'news io'.
>>
I have a read a few other similar questions but have been unable to find an answer, and I do not understand the error message in all honesty. I understand cygwin in a Unix-like interface for windows, but that is about it. I have tried running as administrator, deleting all temp files, restarting etc. but cannot get the pkg to install successfully. Any ideas?
The referenced file 'getxmlattv' is just a function and not a text file as described and cannot be run as a standalone file:
function [retval] = getxmlattv (xmlnode, att)
retval = '';
## Get end of first tag
iend = index (xmlnode, ">");
## Get start of value string. Concat '="' to ensure minimal ambiguity
vals = index (xmlnode, [att '="']);
if (vals == 0)
## Attribute not in current tag
return
elseif (vals)
vals = vals + length (att) + 2;
vale = regexp (xmlnode(vals:end), '"[ >/]');
if (! isempty (vale))
retval = xmlnode(vals:vals+vale-2);
endif
endif
endfunction
I don't see how this is of any use.
For the windows version of octave the packages are already available in the installer
https://wiki.octave.org/Octave_for_Microsoft_Windows
so you don't need to install io from source package. Just re-run the installer
if you missed it.
Please note that the error message is misleading as you are not using the
cygwin version of octave but msys/mingw one; that is based on a modified
version of the cygwin1.dll where they forgot to update the messages:
$ strings msys-1.0.dll | grep cygwin
...
%P: *** Couldn't reserve space for cygwin's heap (%p <%p>) in child, %E
...

fipy viewer not plotting

from fipy import *
nx = 50
dx = 1.
mesh = Grid1D(nx=nx, dx=dx)
phi = CellVariable(name="solution variable",
mesh=mesh,
value=0.)
D = 1.
valueLeft = 1
valueRight = 0
phi.constrain(valueRight, mesh.facesRight)
phi.constrain(valueLeft, mesh.facesLeft)
eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)
timeStepDuration = 0.9 * dx**2 / (2 * D)
steps = 100
phiAnalytical = CellVariable(name="analytical value",
mesh=mesh)
viewer = Viewer(vars=(phi, phiAnalytical),
datamin=0., datamax=1.)
viewer.plot()
x = mesh.cellCenters[0]
t = timeStepDuration * steps
try:
from scipy.special import erf
phiAnalytical.setValue(1 - erf(x / (2 * numerix.sqrt(D * t))))
except ImportError:
print "The SciPy library is not available to test the solution to \
the transient diffusion equation"
for step in range(steps):
eqX.solve(var=phi,
dt=timeStepDuration)
viewer.plot()
I am trying to implement an example from the fipy examples list which is the 1D diffusion problem. but I am not able to view the result as a plot.
I have defined viewer correctly as suggested in the code for the example. Still not helping.
The solution vector runs fine.
But I am not able to plot using the viewer function. can anyone help? thank you!
Your code works fine on my computer. Probably is a problem with a plotting library used by FiPy.
Check if the original example works (just run this from the fipy folder)
python examples/diffusion/mesh1D.py
If not, download FiPy from the github page of the project https://github.com/usnistgov/fipy and try the example again. If not, check if the plotting libraries are correctly installed.
Anyways, you should specify the platform you are using and the errors you are getting. The first time I had some problems with the plotting libraries too.

Can't installing R packages on linux mint 15 32bits

I'm trying to install de ggplot library so I use this command
install.packages('ggplot2', dependencies = TRUE)
When I write library(ggplot2) nothing happens there isn't an error message so I supouse that the installation process work, but when I try to use the gplot function I get this:
Error: could not find function "gplot"
I try to open R Studio as super user and install again, and also try to install the library from the tar.gz package but all the time I get the exact same error.
Thanks in advance
Actually the Function is "qplot" not gplot.
For reference visit:
https://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf
Then go to Page No. 145 and check out for qplot (Quick plot):
Usage:
qplot(x, y = NULL, ..., data, facets = NULL, margins = FALSE,
geom = "auto", xlim = c(NA, NA), ylim = c(NA, NA), log = "",
main = NULL, xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)), asp = NA, stat = NULL, position = NULL)
Perhaps you might try "ggplot()" rather than "gplot()"

Resources