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

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()"

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.

How to write new input file after modify flopy package?

I try to load-if exists, update and write new input files in flopy. I try many things but I can't. Here is my code:
rchFile = os.path.join(modflowModel.model_ws, "hydrogeology.rch")
info = modflowModel.get_nrow_ncol_nlay_nper()
if "RCH" in modflowModel.get_package_list():
rchObject = ModflowRch.load(rchFile, modflowModel)
rchData = rchObject.rech
else:
rchData = dict()
for ts in range(info[3]):
rchData[ts] = np.zeros((info[0], info[1]))
for feat in iterator:
for ts in range(info[3]):
currValue = "random value"
rchData[ts][feat["row"]-1, feat["column"]-1] = currValue
rchObject = ModflowRch(modflowModel, nrchop=3, ipakcb=None, rech=rchData, irch=0, extension='rch', unitnumber=None, filenames="hydrogeology.rch")
rchPath = os.path.join(modflowModel.model_ws, 'rch.shp')
rchObject.export(f=rchPath)
# rchObject.write_file()
# modflowModel.add_package(rchObject)
modflowModel.write_input()
modflowModel is and flopy.modflow.Modflow object. Comments at the end of the codes are lines that I try to write updated new inputs but does not work.
What error(s) are you getting exactly when you say it doesnt work? I routinely modify forcing packages with flopy like this:
m = flopy.modflow.Modflow.load()
for kper in range(m.nper):
arr = m.rch.rech[kper].array
arr *= 0.8 # or something
m.rch.rech[kper] = arr
I found my error. modflowModel.write_input() works very well. Problem occures while loading model object Modflow.load(...). Now I load model whereever I need. Because if I load it another py etc., there might me model_ws confusion.

python3 and libre office calc - setting column width

I am using pyoo to generate reports as open document spreadsheets. pyoo can do everything I require bar setting column widths. Some I want to set as a constant, others as optimal width. From the pyoo website (https://github.com/seznam/pyoo): "If some important feature missing then the UNO API is always available."
A few hours of Googling got me to the class com.sun.star.table.TableColumn which from this page appears to have the properties ("Width" and "OptimalWidth") that I require, but -
>>> x = uno.getClass('com.sun.star.table.TableColumn')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/uno.py", line 114, in getClass
return pyuno.getClass(typeName)
uno.RuntimeException: pyuno.getClass: uno exception com.sun.star.table.TableColumn is unknown
I have no idea whatsoever how to get this to work. The documentation for UNO is overwelming to say the least...
Any clues would be enormously appreciated.
Example Python-UNO code:
def resize_spreadsheet_columns():
oSheet = XSCRIPTCONTEXT.getDocument().getSheets().getByIndex(0)
oColumns = oSheet.getColumns()
oColumn = oColumns.getByName("B")
oColumn.IsVisible = False
oColumn = oColumns.getByName("C")
oColumn.Width = 7000
oColumn = oColumns.getByName("D")
oColumn.OptimalWidth = True
Documentation:
https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Rows_and_Columns
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Columns_and_Rows
EDIT:
From the comment, it sounds like you need to work through an introductory tutorial on Python-UNO. Try http://christopher5106.github.io/office/2015/12/06/openoffice-libreoffice-automate-your-office-tasks-with-python-macros.html.
Thank you Jim K, you pointed me in the right direction, I got it working. My python script generates a ten sheet spreadsheet, and manually adjusting the column widths was becoming a pain. I post below my final code if anyone wants to comment or needs a solution to this. It looks like a pigs breakfast to me combining raw UNO calls and pyoo, but it works I guess.
#! /usr/bin/python3.6
import os, pyoo, time, uno
s = '-'
while s != 'Y':
s = input("Have you remembered to start Calc? ").upper()
os.system("soffice --accept=\"socket,host=localhost,port=2002;urp;\" --norestore --nologo --nodefault")
time.sleep(2)
desktop = pyoo.Desktop('localhost', 2002)
doc = desktop.create_spreadsheet()
class ofic:
sheet_idx = 0
row_num = 0
sheet = None
o = ofic()
uno_localContext = uno.getComponentContext()
uno_resolver = uno_localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", uno_localContext )
uno_ctx = uno_resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
uno_smgr = uno_ctx.ServiceManager
uno_desktop = uno_smgr.createInstanceWithContext( "com.sun.star.frame.Desktop", uno_ctx)
uno_model = uno_desktop.getCurrentComponent()
uno_controller = uno_model.getCurrentController()
uno_sheet_count = 0
for i in range(5):
doc.sheets.create("Page {}".format(i+1), index=o.sheet_idx)
o.sheet = doc.sheets[o.sheet_idx]
o.sheet[0, 0].value = "The quick brown fox jumps over the lazy dog"
o.sheet[1, 1].value = o.sheet_idx
uno_controller.setActiveSheet(uno_model.Sheets.getByIndex(uno_sheet_count))
uno_sheet_count += 1
uno_active_sheet = uno_model.CurrentController.ActiveSheet
uno_columns = uno_active_sheet.getColumns()
uno_column = uno_columns.getByName("A")
uno_column.OptimalWidth = True
uno_column = uno_columns.getByName("B")
uno_column.Width = 1350
o.sheet_idx += 1
doc.save("whatever.ods")
doc.close()

R-program - igraph package error

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

How to get rid of lmer warning message?

I have made some changes to the lmer. It works as it should but I could not get rid of the warning message that pops when I run the program. I have added the following options which allows the program run without stopping but with the warning message. I believe it is the check.nobs.vs.rankZ = "warningSmall" part. How could I get rid of this, any suggestions? Thank you.
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"warningSmall",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),check.scaleX = "ignore",check.formula.LHS="ignore",
## convergence checking options
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL),
check.conv.singular = .makeCC(action = "ignore", tol = 1e-4),
check.conv.hess = .makeCC(action = "warning", tol = 1e-6)
Warning Message from R:
Warning message:
In checkZrank(reTrms$Zt, n = n, control, nonSmall = 1e+06) :
number of observations (=300) <= rank(Z) (=300); the random-effects parameters and the
residual variance (or scale parameter) are probably unidentifiable
You should try check.nobs.vs.rankZ="ignore".
lmerControl doesn't need to specify anything other than the non-default options: at a quick glance, these are your non-default values:
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"ignore",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),
check.scaleX = "ignore",
check.formula.LHS="ignore",
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL))
In general I would suggest it's wise to turn off only the specific warnings and errors you know you want to override -- the settings above look like they could get you in trouble.
I haven't checked this since you didn't give a reproducible example ...

Resources