Bugs item #2224978, was opened at 2008-11-05 11:21 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=453021&aid=2224978&group_id=48422
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: rpy Status: Open Resolution: None Priority: 5 Private: No Submitted By: Conor (kailandifki) Assigned to: Nobody/Anonymous (nobody) Summary: Deleting RPy objects Initial Comment: Hello, two related problems. First of all, why do I have to delete the object r.histlist at the end of the loop in the first snippet of code below? If I do not, then the r.assign function is ignored, and I get the same results over and over. Second, why do I have to "do something" with the r.histlist object before I delete it in the second, larger code snippet below? If I delete the useless lines : r.histlist[0]+=1 r.histlist[0]-=1 I get an error message saying that the object r.histlist does not exist (and therefore cannot be deleted). Regards, CONOR. ~~~~~~~~~~~~~~~~~~ from rpy import r testlist=[3,4,7,2,5,7] r.library("stats") for j in testlist: r.assign('histlist',j) print r.histlist r(""" freq<-c(histlist[0:256]/sum(histlist)) intlist<-c(0:255)""") del r.histlist ~~~~~~~~~~~~~~~~~ listlist=[ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 45, 399, 2559, 11687, 39182, 96319, 177624, 262638, 327388, 376083, 413259, 425285, 404497, 366078, 322999, 280807, 237411, 197816, 163411, 133730, 107215, 83775, 65599, 51165, 41665, 34917, 30284, 26483, 23573, 20757, 18518, 16851, 15058, 13556, 11928, 10893, 9569, 8568, 7508, 6665, 5914, 5182, 4657, 4101, 3679, 3172, 2785, 2428, 2228, 1858, 1583, 1401, 1123, 1049, 868, 754, 608, 538, 392, 290, 289, 229, 171, 148, 134, 82, 80, 57, 38, 44, 32, 20, 17, 12, 15, 9, 7, 6, 7, 3, 6, 7, 2, 3, 2, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 9, 33, 295, 1969, 9613, 34331, 87052, 162771, 239822, 299785, 352484, 402385, 430364, 417884, 378933, 330030, 285064, 247048, 212240, 180614, 147156, 116074, 89835, 69079, 53932, 42736, 35412, 29243, 25666, 22831, 20392, 18323, 16483, 14447, 12690, 11445, 10149, 9017, 7968, 7240, 6679, 5916, 5285, 4748, 4184, 3892, 3413, 3033, 2835, 2462, 2317, 2054, 1770, 1297, 1174, 1005, 872, 687, 593, 517, 396, 355, 242, 227, 182, 150, 123, 101, 75, 73, 59, 54, 38, 35, 22, 25, 9, 16, 9, 4, 7, 11, 2, 2, 2, 1, 2, 2, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] # Let's import all the functions in R from rpy import r # We will need the nonlinear least-squares R package r.library("stats") for j in listlist: # Here we tell R that intense and freq will be used to make the data frame r.assign('histlist',j) r(""" freq<-c(histlist[0:256]/sum(histlist)) intlist<-c(0:255) LogL<-function(p){ alpha<-p[1] mu1<-p[2] mu2<-p[3] sigma1<-p[4] sigma2<-p[5] sum(-1*histlist*log(0.00000001+1/((1+alpha)*sigma1*sqrt(2*pi))*exp(-1*(intlist-mu1)^2/(2*sigma1^2))+alpha/((1+alpha)*sigma2*sqrt(2*pi))*exp(-1*(intlist-mu2)^2/(2*sigma2^2)))) } alpha.start<-0.1 mu1.start<-20 mu2.start<-130 sigma1.start<-7 sigma2.start<-7 out<-optim( c(alpha.start,mu1.start,mu2.start,sigma1.start,sigma2.start), LogL, method="L-BFGS-B", lower=list(0.05,10,10,4.5,4.5), upper=list(0.9,200,200,200,200) ) reslist<-out$par """) r.histlist[0]+=1 r.histlist[0]-=1 del r.histlist print r.reslist del r.reslist ~~~~~~~~~~~~~~~~~~~ ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=453021&aid=2224978&group_id=48422 ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list