[R] How to *completely* stop a script after stop()?

2011-01-15 Thread Marius Hofert
Dear expeRts,

is there a neat way to *completely* stop a script after an error occured?
For example, consider the following script:

##  file.R 

for(i in 1:10){
print(i)
if(i == 5) stop("i == 5")
}
for(i in 11:100) print(i)

## 

stop() behaves like it should namely to stop the execution of the *current*
expression, but I was wondering if it is possible to *really* stop the script 
after 
the first for loop [so without executing the second for loop or anything after 
that
point]. Of course one could use something like "if(there was an error) do not 
continue"
but that's not really nice.

Cheers,

Marius
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] CSV value not being read as it appears

2011-01-15 Thread bgreen
David,

Thanks. When I am back at work I will try to find out some specifics
regarding the original data base and how the reports are generated. The
differencs are not apparent via manual inspection.

I will look at the csv file in an editor as well and look into xlsReadWrite.

I agree EXCEL formatting of dates can be a problem.

regards

Bob

> I am a bit confused by this. You are doing a transfer from Excel (.xls
> or .xlsx) to .csv, then a subset in R and ending up with a couple of
> entries which are " Open" rather than "Open". So where are they coming
> from? You say they are not in the original Excel, so that suggests the
> transfer to .csv is the problem. I would be very surprised if the subset
> was a problem, but as others have indicated transfer to .csv can be
> downright ugly.
>
> You can check the .csv file by opening it in an editor (I use Emacs).
> Just go to the line and have a look if the extra space is there nestling
> between two commas.
>
> The other advice is, don't go through .csv. Go directly from Excel to R.
> My favourite tools are RODBC and xlsReadWrite for that step. Both work
> extremely well.
>
> As others have indicated, the big bugbear in the .csv route is dates, or
> what Excel decides are dates. My experience was the conversion of New
> Zealand health ID numbers to dates. They are three letters then 4
> digits, so AUG2699 became a date.
>
> David Scott
>
> On 14/01/2011 10:58 p.m., bgr...@dyson.brisnet.org.au wrote:
>> Hello David,
>>
>> Thanks for your e-mail. The data was a report derived from a statewide
>> database, saved in EXCEL format, so the usual issue of the vagaries of
>> human data entry variation wasn't the issue as the data was an automated
>> report, which is run every three months. I would not have even noticed
>> this problem if I hadn't been double checking the numbers of people by
>> district. Visual inspection didn't reveal this problem - no white space
>> was obvious and the spelling was identical. Tabulation via R wouldn't
>> have
>> detected this - I was obtaining the EXCEL totals via filter which I then
>> compared with R output. I'm hoping I can skip this step, in future, with
>> Jim's suggestion.
>>
>> regards
>>
>> Bob
>>
>>
>>> As a further note, this is a reminder that whenever you get data via a
>>> spreadsheet the first thing to do is examine it and clean up any
>>> problems. A basic requirement is to tabulate any categorical variable.
>>> Spreadsheets allow any sort of data to be entered, with no controls. My
>>> experience is that those who enter data into spreadsheets enter all
>>> sorts of variations of what a human would wish to treat as the same
>>> ("Open", "Open  ", "open", etc.), even when told not to.
>>>
>>> David Scott
>>>
>>> On 14/01/2011 4:03 p.m., Jim Holtman wrote:
 try strip.white=TRUE to strip out white space

 Sent from my iPad

 On Jan 13, 2011, at 21:44, bgr...@dyson.brisnet.org.au wrote:

>
> I have a frustrating issue which I am hoping someone may have a
> suggestion
> about.
>
> I am running XP and R 2.12.0 and saved an EXCEL file that I was sent
> as
> a
> csv file.
>
> The initial code I ran follows.
>
> dec<- read.csv("g://FMH/FO30122010.csv",header=T)
> dec.open<- subset (dec, Status == "Open")
> table(dec.open$AMHS)
>
> I was checking the output and noticed a difference between my manual
> count
> and R output. Two subject's rows were not being detected by the
> subset
> command:
>
> For the AMHS where there was a discrepancy I then ran:
> wm<- subset (dec, AMHS == "WM")
>
> The problem appears to be that there is a space before the 'Open"
> value
> for two indivduals, as per the example below.
>
> 10/02/2010  Open
> 22/08/2007   Open
>
> Checking in EXCEL there does not appear to be a space and the format
> is
> the same (e.g 'general').  I resolved the problem by copying over the
> values for the two individuals where I identified  a problem.
>
> Given this problem was not detected by visual scanning I would
> appreciate
> advice on how this problem can be detected in future without my
> having
> to
> manually check raw data against R output.
>
> Any assistance is appreciated,
>
> Bob
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>> --

[R] Question about scatterplot in package car

2011-01-15 Thread David Perlman
I am getting an error message from scatterplot:

> library(car)
> scatterplot(Prestige$income~Prestige$type)
Error in Summary.factor(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,  : 
  range not meaningful for factors
In addition: Warning message:
In Ops.factor(x[floor(d)], x[ceiling(d)]) : + not meaningful for factors
> 

The command does output the kind of graph that I want (boxplots).

I just did install.packages("car") so I believe I have the latest version.

More generally, the reason I am trying to do this is because I am trying to 
generate a boxplot with case number labels on the outlier points.  I initially 
tried to do it with the base boxplot() but the returned values of the outliers 
do not include enough information to actually identify which cases those points 
came from.  Scatterplot in car seems like it should be able to do the trick, 
but I haven't been able to figure out how to get it to work.

The following command works as expected:
scatterplot(Prestige$income~Prestige$prestige, id.n=4)

but this command does not label anything:
scatterplot(Prestige$income~Prestige$type, id.n=4)
and also produces the same error.

Furthermore, even if that did work, what I really want is for the points 
already identified as outliers to be labeled, but I have not been able to 
figure out how to do that.  I am not sure if that is because I am confused, or 
because scatterplot() isn't working right!

Any help with how to do this would be greatly appreciated.  Thanks in advance!

--
-dave
"Pseudo-colored pictures of a person's brain lighting up are 
undoubtedly more persuasive than a pattern of squiggles produced by a
polygraph.  That could be a big problem if the goal is to get to the
truth."  -Dr. Steven Hyman, Harvard

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] write.dta and export of variable labels

2011-01-15 Thread Andrew Owen
When I import a data file in stata format using read.dta, the full variable
labels (e.g. variable= "inc2000"; variable label= "Total household income in
year 2000"). When I then export the same data file using write.dta, the
variable labels are not included in the new .dta file. Is there any way to
ensure that the variable labels are maintained?

Thanks

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] test

2011-01-15 Thread romzero

Thank you all for the precious help.

Finally i could start the writing of a first part of my script, but now i
have a new question for you.

Need i to repeat the write.table portion for all the 15 lines or can i use a
"short cut"?

Example:

file.open <- "C:\\test.txt"
file.save <- "C:\\results.txt"

my.data <- read.table(file, header=T)

library(plyr)
write.table(ddply(my.data, .(Thesis, Day), function(x){
Baseline <- unlist(x[1, c("A", "B", "C")])
data.frame(t(apply(x[-1, c("A", "B", "C")], 1, function(z){z -
Baseline})))
}), file = file.save, row.names = F) 
write.table(ddply(my.data, .(Thesis, Day), function(x){
Baseline <- unlist(x[2, c("A", "B", "C")])
data.frame(t(apply(x[-1:-2, c("A", "B", "C")], 1, function(z){z -
Baseline})))
}), file = file.save, append = T, row.names = F, col.names = F) 
etc etc

Thanks again for the help.

Best regards,
Roberto.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Comparison-of-numbers-in-a-table-tp3217329p3218524.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Truetype and Opentype font in pdf device

2011-01-15 Thread Kohske Takahashi
Deal all,

I want to know if truetype or opentype fonts are available in pdf
device (i.e., pdf() or dev.copy2pdf()), and if so, how to do it?

Now I can do as followings:

1. convert ttf to afm using ttf2afm, e.g.: $ ttf2afm Impact.ttf > Impact.afm
2. put the afm file in $R_HOME/library/grDevices/afm
3. register a new type1 font: pdfFonts(Impact=Type1Font("Impact",
rep("Impact.afm", 4), encoding = "TeXtext.enc"))
4. specify the fontfamily in gpar: grid.text('hello grid world',
gp=gpar(fontfamily="Impact"))

but obviously, it is better if truetype or opentype fonts are directly
available without conversion to type1 font.

Also, I found that Cairo package can handle truetype or opnetype font.
However, the package seems not to support fontfamily, hence I cannot
use it through gpar.

Does anyone know about this topic?

Thank you in advance.

--
Kohske Takahashi 

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Selecting the first occurrence of a value after an occurrence of a different value

2011-01-15 Thread surreyj

Thanks so much for your help everyone, got it sorted now :)

this is what I used in the end:

timeofonlyfirstresponseafterrft<-testdata$Time[test<-which(!diff(as.numeric(factor(Stat,
levels = c("MagDwn", "Resp")]
timeofonlyfirstresponseafterrft1<-as.POSIXct(timeofonlyfirstresponseafterrft,
origin="timeofstart[1]", format="%Y,%m,%d, %H, %M, %OS")

Cheers

Surrey
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Selecting-the-first-occurrence-of-a-value-after-an-occurrence-of-a-different-value-tp3217340p3218653.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to *completely* stop a script after stop()?

2011-01-15 Thread Taras Zakharko

I take you don't use source() to execute your scripts. When using source,
stop() aborts the complete script, just as you indent to. 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-completely-stop-a-script-after-stop-tp3218808p3218823.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems with TeachingDemos package

2011-01-15 Thread gaiarrido

R2wd is working but i received an alarm:

> wdtxtStart()
Error en R2wd::wdGet() : tentativa de aplicar una no-función 
 The translation is "attempt to apply a no-function"



-
Mario Garrido Escudero
PhD student
Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca.
Agrícola
Universidad de Salamanca
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problems-with-TeachingDemos-package-tp3218266p3218935.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question about scatterplot in package car

2011-01-15 Thread John Fox
Dear David,

scatterplot() isn't intended to produce parallel boxplots with a factor on
the RHS of the formula (though that's a reasonable feature request) but
rather, as the name implies, to make scatterplots. For boxplots with
labelled outliers, use the car function Boxplot(), as in Boxplot(income ~
type, data=Prestige). Note that you can use a data argument with both
scatterplot() and Boxplot(), and doing so has the advantage of providing
point labels from the row names of the data frame. See ?Boxplot and
?scatterplot (and the book with which the package is associated) for
details.

I hope this helps,
 John



John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of David Perlman
> Sent: January-14-11 6:37 PM
> To: r-help@r-project.org
> Subject: [R] Question about scatterplot in package car
> 
> I am getting an error message from scatterplot:
> 
> > library(car)
> > scatterplot(Prestige$income~Prestige$type)
> Error in Summary.factor(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,  :
>   range not meaningful for factors
> In addition: Warning message:
> In Ops.factor(x[floor(d)], x[ceiling(d)]) : + not meaningful for factors
> >
> 
> The command does output the kind of graph that I want (boxplots).
> 
> I just did install.packages("car") so I believe I have the latest
> version.
> 
> More generally, the reason I am trying to do this is because I am trying
> to generate a boxplot with case number labels on the outlier points.  I
> initially tried to do it with the base boxplot() but the returned values
> of the outliers do not include enough information to actually identify
> which cases those points came from.  Scatterplot in car seems like it
> should be able to do the trick, but I haven't been able to figure out
> how to get it to work.
> 
> The following command works as expected:
> scatterplot(Prestige$income~Prestige$prestige, id.n=4)
> 
> but this command does not label anything:
> scatterplot(Prestige$income~Prestige$type, id.n=4) and also produces the
> same error.
> 
> Furthermore, even if that did work, what I really want is for the points
> already identified as outliers to be labeled, but I have not been able
> to figure out how to do that.  I am not sure if that is because I am
> confused, or because scatterplot() isn't working right!
> 
> Any help with how to do this would be greatly appreciated.  Thanks in
> advance!
> 
> --
> -dave
> "Pseudo-colored pictures of a person's brain lighting up are undoubtedly
> more persuasive than a pattern of squiggles produced by a polygraph.
> That could be a big problem if the goal is to get to the truth."  -Dr.
> Steven Hyman, Harvard
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] getting R-readable data , not pictures, from US OTS "data" pages

2011-01-15 Thread Mike Marchywka

Does anyone know offhand if the OTS has an FTP site or other pages
off in a corner somewhere to make data downloading and integration with
R easy? They have mailing lists to which you can subscribe that announce new
data but then you get these things like PDF files
with tables of numbers and the PR releases don't obviously
have links to related csv or other data files. For example,

http://www.ots.treas.gov/?p=StatisticalReleases&ContentRecord_id=1bd8494f-0909-404b-8048-1468f754537f

after surfing for a few moments on their website I still didn't
find any ASCII data files. Now, of course I can run pdftotext on the pdf,
historically with pdf's this has been a huge accomplishment, 
and play games with the jumbled text for a while but I thought there may be a 
better approach.

If there is enough demand maybe they could put a link to csv files into PR just 
as with the
pdf file. Tabular pictures are nice but I would imagine R users would benefit 
if computer readable
data was readily available too. Many gov sites have real data and maybe I just 
need more coffee. 

Thanks.



note new address
Mike Marchywka
487 Salem Woods Drive
Marietta GA 30067
415-264-8477 (w)<- use this
404-788-1216 (C)<- leave message
989-348-4796 (P)<- emergency only
marchy...@hotmail.com
Note: If I am asking for free stuff, I normally use for hobby/non-profit
information but may use in investment forums, public and private.
Please indicate any concerns if applicable.



  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Rounding variables in a data frame

2011-01-15 Thread Pete B

Bill, Joshua, Phil

Thanks for the suggestions.  Very much appreciated.

Kind regards

Pete
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Rounding-variables-in-a-data-frame-tp3218729p3219060.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Rounding variables in a data frame

2011-01-15 Thread Joshua Wiley
On Fri, Jan 14, 2011 at 11:16 PM, Phil Spector
 wrote:
> Is sapply really necessary here?

Apparently not, and it is certainly more cumbersome.  Because data
frames can contain a mix of classes, I thought that round() did not
have a method for them (in retrospect that does not make much sense).
I had also not seen Dr. Venables reply.

>
>> exc = !names(d) %in% "d3"

Thanks for sharing---this circumvents the other problem I had of
needing to pass the actual character names.

>> d[,exc] = round(d[,exc])
>> d
>
>   d1 d2         d3 d4
> 1  10  6  2.3749642 -4
> 2  11  6 -0.2081097 -2
> 3  10  4  1.2675955 -4
> 4  10  8  1.2468859 -2
> 5  10  6  2.7193027 -4
> 6   9  6  1.9195531 -5
> 7   9  6  2.8188036 -6
> 8  10  7  2.5755148 -4
> 9  11  5  2.4037376 -6
> 10 11  5  3.4295063 -5
>
>                                        - Phil Spector
>                                         Statistical Computing Facility
>                                         Department of Statistics
>                                         UC Berkeley
>                                         spec...@stat.berkeley.edu

Thanks,

Josh
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R scheduling request

2011-01-15 Thread Alessandro Oggioni
Dear all,
I have used R.rps to produce a Google API chart (googleVis) with a
data request in another server.
But i don't understand how is possible to scheduling a request data
to the server and after produce a update of the charts.
Thanks in advance.
Alessandro Oggioni

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] access to right time unit when checking for time execution

2011-01-15 Thread Christine SINOQUET

Hello,

I really wonder how to distinguish between secs and mins in the example 
below.


In other terms, how can I access the time unit in variable d ?

start1 <- Sys.time();
stop1 <- Sys.time(); d <- stop1-start1; print(d); 
v<-unlist(strsplit(as.character(d), split=" ")); print(v)

Time difference of 3.024054 secs
[1] "3.02405381202698"

stop1 <- Sys.time(); d <- stop1-start1; print(d);
v <- unlist(strsplit(as.character(d), split=" ")); print(v)
Time difference of 3.189143 mins
[1] "3.18914334774017"


Thank you in advance for your kind help.

C.S.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] piecewise regression

2011-01-15 Thread Federico Bonofiglio
Thank u Doctor Muggeo,
I was just getting familiar with your package this morning..i find it
interesting 'cause so far is the only one that allows estimations for the
single slope parameters between brakepoints, by the slope() function.
Contrarily, supposing only one knot in a linear regression,I don't
understand why the anova tables would consider meaningless showing the
p-value for the 2nd stick slope...
Also in other packages (splines, gss) I have found that dominates the same
indifference toward the "remaining" stick's slope coefficient's
estimation/inference...
I think this is a crucial aspect left unchecked .
Consider a slightly L shaped trend in a scatterplot where while fixing one
knot at the presumed L conjunction we would have that the left regressd
slope had a significant coefficient (different from zero) while the
rightmost not...,and I think this would be a crucial information in the
scenario of some time trend analysis since we would be able to say that on
the knot leftside the relation time-response was significant while on the
right not..

Well if I haven't mistaken myself I think this is a hardly extrapolating
info from the current summary displays.
am I too trivial or i'm actually missing somenthing??

thank u if u wish an answer..i'm quite puzzled on that point






2011/1/15 vito.muggeo 

> dear all,
> The package segmented allows to estimate piecewise linear relationships
> (*connected*
> lines, i.e. a gradual change in the slope) with several breakpoints (known
> or unknown)
> within (generalized) linear models..
> The package also includes some functions for plotting and testing..
>
> Have a look to
> library(help=segmented)
> ?segmented
>
> and references therein (there is a Rnews paper that could be useful..)
>
> vito
>
> PS If I remember correctly strucchange fits "piecewise constant" models,
> i.e. sudden
> changes in the intercept.
>
>
> 
> Vito M.R. Muggeo
> Dip.to Sc Statist e Matem `Vianelli'
> Università di Palermo
> viale delle Scienze, edificio 13
> 90128 Palermo - ITALY
> tel: 091 23895240
> fax: 091 485726/485612
> http://dssm.unipa.it/vmuggeo
> 
>
> On Fri, 14 Jan 2011 14:14:26 -0500, John Sorkin wrote
> > If you know  the knot and want linear segments, lm (or any other "normal"
> > regression software) can perform the analysis. For example if you want to
> > regress y  on x and have a knot a 20 the following code will work:
> >
> > x <- runif(500,0,40)
> > plot(x)
> >
> > for (i in 1:500) {
> > if (x[i] < 20)  y[i] <- (-0.5*x[i])+rnorm(1)
> > if (x[i] >= 20) y[i] <- ( 0.5*x[i])+rnorm(1) -20
> > }
> >
> > plot(x,y)
> >
> > knot <- 20
> > aboveknot <- pmax(x-knot,rep(0,500))# will be 0 for x < 20, x for x >20
> > fit1 <- lm(y~x+aboveknot)
> > summary(fit1)
> >
> > The analysis will give you three parameters
> > (1) the intercept
> > (2) the slope of below 20
> > (3) the difference between the slope below 20 and above 20
> >
> > John
> >
> > John Sorkin M.D., Ph.D.
> > Chief, Biostatistics and Informatics
> > Baltimore VA Medical Center GRECC,
> > University of Maryland School of Medicine Claude D. Pepper OAIC,
> > University of Maryland Clinical Nutrition Research Unit, and
> > Baltimore VA Center Stroke of Excellence
> >
> > University of Maryland School of Medicine
> > Division of Gerontology
> > Baltimore VA Medical Center
> > 10 North Greene Street
> > GRECC (BT/18/GR)
> > Baltimore, MD 21201-1524
> >
> > (Phone) 410-605-7119
> > (Fax) 410-605-7913 (Please call phone number above prior to faxing)
> > jsor...@grecc.umaryland.edu
> >
> > >>> Gene Leynes > 1/14/2011
> 11:50 AM >>>
> > oh yes, and the structchange package.
> >
> > After a day of experimentation I couldn't figure out how to get the
> > structchange package to work for my problems.  Although it is probably
> user
> > error on my part, the package seems to be specific to time series
> problems.
> > Also, I think it needed regularly spaced x's... but maybe that would be a
> > good thing to look at as part of a two step approach (smoothing first to
> get
> > regularly spaced data).
> >
> > PS:  Actually, I just noticed that there are some other help topics that
> I
> > had not read yet which went up last November.
> > http://r-project.markmail.org/thread/npjhlwwt6oh3sby3
> >
> > On Fri, Jan 14, 2011 at 10:25 AM, Spencer Graves <
> > spencer.gra...@structuremonitoring.com> wrote:
> >
> > > Hello:
> > >
> > >
> > >  I just found 58 help pages in 32 contributed packages containing
> the
> > > terms "piecewise" and "regression", as follows:
> > >
> > >
> > > library(sos)
> > > pr <- ???'piecewise regression' # for "piecewise" with "regression"
> > > summary(pr) # 58 matches in 32 packages
> > > pr # view the 58 links sorted by package in a web browser
> > >
> > > p.r <- ???"{piecewise regression}" # for "piecewise" followed immediate
> by
> > > "regression"
> > > summary(p.r) # 15 matches in 13 packages
> > > p.4 # to view in a web brows

Re: [R] Help on a Display function

2011-01-15 Thread Hans W Borchers
William Dunlap  tibco.com> writes:
> 
> But it fails on this:
>   > my_names <- c("Bill", "William")
>   > display(rev(my_names))
>   rev(my_names) = Error in cat(list(...), file, sep, fill, labels,
> append) : 
> argument 3 (type 'list') cannot be handled by 'cat'
> This is because you call eval() using the environment of the
> function, while ordinary argument evaluation evaluates them
> in the environment of the caller.   Do not use eval() directly
> but use the ordinary evaluation that R does automatically. 

I appreciate this extensive answer.
So I decided to use the following function, suppressing the deparsed form
if there is a tag (while I'm inclined to forbid function code as input):

display <- function (...) {
evaluatedArgs <- list(...)
n <- length(evaluatedArgs)
argTags <- names(evaluatedArgs)
deparsedArgs <- lapply(substitute(placeholderFunction(...))[-1], 
function(expr) {
d <- deparse(expr)
paste(d, collapse = "\n")
}
)
if (is.null(argTags)) argTags <- rep("", n)
namedArgs <- ifelse(argTags != "", argTags, deparsedArgs)
cat(paste(namedArgs, evaluatedArgs, sep=" = "), sep = "\n")
}

It works fine on your examples,

my_names <- c("Bill", "William")
display(x=log(10), 1+2+3, sin(1), rev(my_names),
z=(function(p){lp<-log(p);lp+lp^2/2+lp^3/6})(0.2))
# x = 2.30258509299405
# 1 + 2 + 3 = 6
# sin(1) = 0.841470984807897
# rev(my_names) = c("William", "Bill")
# z = -1.00911130949159

while there still are problems with matrices (and probably other structures):

A <- matrix(1:4, 2, 2); B=diag(4)
display(A, B)
# A = 1:4
# B = c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)

I guess I have to define my own output representation in these cases, based
on "lapply(evaluatedArgs, class)".

Many thanks, Hans Werner

>   display2 <- function (...) 
>   {
>   evaluatedArgs <- list(...)
>   argTags <- names(evaluatedArgs)
>   deparsedArgs <- lapply(substitute(placeholderFunction(...))[-1], 
>   function(expr) {
>   d <- deparse(expr)
>   paste(d, collapse = "\n") # or d[1] or ...
> })
>   # use if(is.null(argTags)) ... cat without argTags ... ?
>   cat(paste(sep = " = ", argTags, deparsedArgs, evaluatedArgs), 
>   sep = "\n")
>   }
>   > my_names <- c("Bill", "William")
>   > display2(rev(my_names))
>= rev(my_names) = c("William", "Bill")
>   > display2(strings=rev(my_names))
>   strings = rev(my_names) = c("William", "Bill")
>   > display2(x=log(10), 1+2+3,
> z=(function(p){lp<-log(p);lp+lp^2/2+lp^3/6})(0.2))
>   x = log(10) = 2.30258509299405
>= 1 + 2 + 3 = 6
>   z = (function(p) {
>   lp <- log(p)
>   lp + lp^2/2 + lp^3/6
>   })(0.2) = -1.00911130949159
> 
> > 
> > My questions:
> > 
> > (1) Is there a better or more appropriate way to write such a 
> > function? ---
> > I'm not so well versed in internal R functions such as 
> > (de)parse(),
> > substitute(), or eval().
> > 
> > (2) What is the role of the "placeholderFunction"? I could 
> > not find enough
> > information about it resp. about the whole construction.
> 
> The function
>   f <- function(x) substitute(func(x))
> produces an object of class "call" whose first element
> is the name "func" and whose subsequent elements are
> the arguments in the call.  The [-1] strips off the
> function name.  You might also do
>   f <- function(x) substitute((x))
> which produces an object of class "(" whose first element
> is the name "(" which you can strip off.  "(" is easier
> to misread and "(" objects must have length 2, while
> call objects have any length greater than 0.
> 
> I learned about this by playing around with the output of
> quote() (or parse() or substitute() or expression()).  Look
> at the class, length, and [[elements]] of expressions.
> The following str.language might get you started.  It prints
> the name, class, length, and a summary of the value of each
> part of an expression.
> 
> [...]
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com 
> 
> > 
> > Thanks, Hans Werner
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] access to right time unit when checking for time execution

2011-01-15 Thread Uwe Ligges



On 15.01.2011 12:57, Christine SINOQUET wrote:

Hello,

I really wonder how to distinguish between secs and mins in the example
below.

In other terms, how can I access the time unit in variable d ?

start1 <- Sys.time();
stop1 <- Sys.time(); d <- stop1-start1; print(d);
v<-unlist(strsplit(as.character(d), split=" ")); print(v)
Time difference of 3.024054 secs
[1] "3.02405381202698"

>

stop1 <- Sys.time(); d <- stop1-start1; print(d);
v <- unlist(strsplit(as.character(d), split=" ")); print(v)
Time difference of 3.189143 mins
[1] "3.18914334774017"




1. If you want to measure execution time, use system.time().
2. If you want to calculate a time difference, use difftime() and 
specify the unit:

difftime(stop1, start1, units="mins")

Best,
Uwe Ligges









Thank you in advance for your kind help.

C.S.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] interactive graphics from the O/S Shell prompt

2011-01-15 Thread analys...@hotmail.com
I have a function called plotID(ID) that would generate a plot for
customerID = "ID".  I can run it repeatedly from within R without any
problems.

Would it be possible to run this function from the O/S command prompt;
each time you enter an ID , it would open a graphics window with the
plot for that ID and prompt you for a new ID (and perhaps if you type
"quit" the program terminates).

Thanks.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] access to right time unit when checking for time execution

2011-01-15 Thread David Winsemius


On Jan 15, 2011, at 6:57 AM, Christine SINOQUET wrote:


Hello,

I really wonder how to distinguish between secs and mins in the  
example below.


In other terms, how can I access the time unit in variable d ?

start1 <- Sys.time();
stop1 <- Sys.time(); d <- stop1-start1;


> str(d)
Class 'difftime'  atomic [1:1] 0.00343
  ..- attr(*, "units")= chr "secs"
> attr(d, "units")
[1] "secs"



print(d); v<-unlist(strsplit(as.character(d), split=" ")); print(v)
Time difference of 3.024054 secs
[1] "3.02405381202698"

stop1 <- Sys.time(); d <- stop1-start1;

# Wait a bit...
> d
Time difference of 1.053085 mins
> stop1 <- Sys.time(); d <- stop1-start1
> attr(d, "units")
[1] "mins"


print(d);
v <- unlist(strsplit(as.character(d), split=" ")); print(v)
Time difference of 3.189143 mins
[1] "3.18914334774017"


Thank you in advance for your kind help.

C.S.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] interactive graphics from the O/S Shell prompt

2011-01-15 Thread David Winsemius


On Jan 15, 2011, at 9:42 AM, analys...@hotmail.com wrote:


I have a function called plotID(ID) that would generate a plot for
customerID = "ID".  I can run it repeatedly from within R without any
problems.

Would it be possible to run this function from the O/S command prompt;
each time you enter an ID , it would open a graphics window with the
plot for that ID and prompt you for a new ID (and perhaps if you type
"quit" the program terminates).



?Rscript



Thanks.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] piecewise regression

2011-01-15 Thread Achim Zeileis

On Sat, 15 Jan 2011, vito.muggeo wrote:


dear all,
The package segmented allows to estimate piecewise linear relationships 
(*connected*
lines, i.e. a gradual change in the slope) with several breakpoints (known or 
unknown)
within (generalized) linear models..
The package also includes some functions for plotting and testing..

Have a look to
library(help=segmented)
?segmented

and references therein (there is a Rnews paper that could be useful..)

vito

PS If I remember correctly strucchange fits "piecewise constant" models, 
i.e. sudden changes in the intercept.


In the simplest case, yes.

More generally, the breakpoints() function in "strucchange" estimates 
points at which all coefficients of a linear regression model change. This 
may be just an intercept but can also include more effects. Unlike in 
"segmented" there is no restriction that the resulting regression curves 
are continuous.

Z




Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726/485612
http://dssm.unipa.it/vmuggeo


On Fri, 14 Jan 2011 14:14:26 -0500, John Sorkin wrote

If you know  the knot and want linear segments, lm (or any other "normal"
regression software) can perform the analysis. For example if you want to
regress y  on x and have a knot a 20 the following code will work:

x <- runif(500,0,40)
plot(x)

for (i in 1:500) {
if (x[i] < 20)  y[i] <- (-0.5*x[i])+rnorm(1)
if (x[i] >= 20) y[i] <- ( 0.5*x[i])+rnorm(1) -20
}

plot(x,y)

knot <- 20
aboveknot <- pmax(x-knot,rep(0,500))# will be 0 for x < 20, x for x >20
fit1 <- lm(y~x+aboveknot)
summary(fit1)

The analysis will give you three parameters
(1) the intercept
(2) the slope of below 20
(3) the difference between the slope below 20 and above 20

John

John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence

University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524

(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
jsor...@grecc.umaryland.edu


Gene Leynes  1/14/2011 11:50 AM >>>

oh yes, and the structchange package.

After a day of experimentation I couldn't figure out how to get the
structchange package to work for my problems.  Although it is probably user
error on my part, the package seems to be specific to time series problems.
Also, I think it needed regularly spaced x's... but maybe that would be a
good thing to look at as part of a two step approach (smoothing first to get
regularly spaced data).

PS:  Actually, I just noticed that there are some other help topics that I
had not read yet which went up last November.
http://r-project.markmail.org/thread/npjhlwwt6oh3sby3

On Fri, Jan 14, 2011 at 10:25 AM, Spencer Graves <
spencer.gra...@structuremonitoring.com> wrote:


Hello:


 I just found 58 help pages in 32 contributed packages containing the
terms "piecewise" and "regression", as follows:


library(sos)
pr <- ???'piecewise regression' # for "piecewise" with "regression"
summary(pr) # 58 matches in 32 packages
pr # view the 58 links sorted by package in a web browser

p.r <- ???"{piecewise regression}" # for "piecewise" followed immediate by
"regression"
summary(p.r) # 15 matches in 13 packages
p.4 # to view in a web browser


 Beyond this, the "structchange" package supports looking for changes
that would be, e.g., linear in one segment then jump to a different linear
regime.  If you want the lines to connect, then you may want splines.
 Probably the most common spline is cubic, but you can also get linear
splines.  One of the most general spline packages is "fda" (functional data
analysis), with multiple companion books by James Ramsay and others.
 However, there are other spline packages.


 If this does not answer your question, "PLEASE do read the posting
guide http://www.R-project.org/posting-guide.html and provide commented,
minimal, self-contained, reproducible code", as it says in the signature
block for each email on this list.


 Hope this helps.
 Spencer Graves



On 1/14/2011 6:42 AM, Federico Bonofiglio wrote:


Hello everybody

Quick question, if you'd like to throw a little tip:
 does anyone knows a function that runs piecewise regression models with
coefficients estimation and inferences ?

Thank you

   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reprod

Re: [R] survreg vs. aftreg (eha) - the relationship between fitted coefficients?

2011-01-15 Thread Andrew Jackson

Dear Göran 

I too have been working on this for the last couple of weeks and this is a
great help thanks. I wonder can you advise on how the covariance matrix of
estimated parameters in phreg relates to those estimated in survreg.

Im hoping you can just put your finger on this. Your eha package has been
really useful so far and if I can get this working then i will be a very
happy person indeed.  Essentially, I am doing all this in order to run
phreg, then convert and pass the results to a survreg object in order to use
the predict function to create survival curves for each stratification with
confidence intervals around them. This is clunky I know, but unless there is
a similar predict method for phreg objects I am stuck, and I havent found
one yet.

What follow is a piece of code ive been working on to explore the
relationships between phreg and survreg outputs using simulated data.

#
--
# START OF SCRIPT EXAMPLE
#
--
rm(list=ls()) # clear the memory
graphics.off() # turn graphics off

set.seed(1) # for repeatability, set the random number seed

# Load the libraries
library(survival)
library(eha)

#
--

n <- 50 # number of observations per stratification
true.shape <- c(3,3,3,3)  # common shape parameter for each category
true.scale <- c(3,5,7,20) # separate scale parameter
X1.code <- c("A","A","B","B") # X1 encoded as A or B
X2.code <- c("P","Q","P","Q") # X2 encoded as P or Q

# Create the response variables and two fixed factor variables
Y <- NULL
X1 <- NULL
X2 <- NULL

# Loop over each combinatin of Factors and simulate some data from a 
# weibull distribution
for (i in 1:length(true.shape)){
  
  # simulate the Y data
  tmp <- rweibull(n,true.shape[i],scale=true.scale[i])
  Y <- c(Y,tmp)
  
  # Encode the fixed factors
  X1 <-c (X1,rep(X1.code[i],n))
  X2 <-c (X2,rep(X2.code[i],n))
  
}  # close loop over factors

# X1 and X1 are factors
X1 <- as.factor(X1)
X2 <- as.factor(X2)

# Everyone has status 1 here (i.e. they were all observed to death/failure)
status <- rep(1,length(Y))


#
--
# plot the data
dev.new()
plot(survfit(Surv(Y,status)~X1+X2),"All Data")

# run survreg
m.surv <- survreg(Surv(Y,status)~X1*X2,dist="weibull")

# run phreg
m.ph <- phreg(Surv(Y,status)~X1*X2,dist="weibull")

# Covariance matrix for survreg() method
m.surv$var

# Covariance matrix for phreg() method
m.ph$var

#
--
# And these are the type of plots i want to produce.

new.data <- data.frame(X1=factor("B",levels=levels(X1)),
X2=factor("Q",levels=levels(X2)))
prob <- seq(0.0, 1.0, length=200)
temp <- predict(m.surv, type='quantile', p=prob, se.fit=T, newdata=new.data)
matlines(cbind(temp$fit, temp$fit +1.96*temp$se,
   temp$fit - 1.96*temp$se),  1-prob, 
   lty=c(1,2,2), col=2, lwd=1)

#
--
# END OF SCRIPT EXAMPLE
#
--



As far as I can decipher the following are related:

var(log(shape)) from phreg equates directly to var(log(scale)) from survreg

var(log(scale)) = var(Intercept)

-cov(log(shape),log(scale) = cov(Intercept,log(scale)) # note the minus in
front of the phreg output

I am stuck though now on how the following relate

The variances of the covariates
var(X1B)
var(X2Q)
var(X1B:X2Q)

The covariance of the covariates
cov(X1B,X2Q)
cov(X1B:X2Q,X1B)
cov(X1B:X2Q,X2Q)

The covariance of the covariates with the shape and scale parameters
cov(log(shape),X1B)
cov(log(scale),X1B)
.. and similary with X2Q and X1B:X2Q

I look forward to hearing from you on this.

best wishes
Andrew Jackson

-- 
Dr Andrew Jackson
Lecturer
School of Natural Sciences
Zoology Building, Trinity College Dublin, Dublin 2, Ireland 
Tel. + 353 1 896 2728, Fax. + 353 1 677 8094, Email. a.jack...@tcd.ie
http://www.tcd.ie/Zoology/research/research/theoretical/AndrewJackson.php

-- 
View this message in context: 
http://r.789695.n4.nabble.com/survreg-vs-aftreg-eha-the-relationship-between-fitted-coefficients-tp3082263p3219204.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to *completely* stop a script after stop()?

2011-01-15 Thread Carl Witthoft


Somehow this reminds me of a famous FORTRAN code snippet:

10 STOP
STOP
STOP
! IN CASE STILL SKIDDING
GOTO 10




From: Marius Hofert 
Date: Sat, 15 Jan 2011 09:09:20 +0100


Dear expeRts,

is there a neat way to *completely* stop a script after an error 
occured? For example, consider the following script:


##  file.R 

for(i in 1:10){

print(i)
if(i == 5) stop("i == 5")


}
for(i in 11:100) print(i)

## 


stop() behaves like it should namely to stop the execution of the 
*current* expression, but I was wondering if it is possible to *really* 
stop the script after the first for loop [so without executing the 
second for loop or anything after that point]. Of course one could use 
something like "if(there was an error) do not continue" but that's not 
really nice.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to *completely* stop a script after stop()?

2011-01-15 Thread Mike Marchywka











> Date: Sat, 15 Jan 2011 11:29:20 -0500
> From: c...@witthoft.com
> To: r-help@r-project.org
> Subject: [R] How to *completely* stop a script after stop()?
>
>
> Somehow this reminds me of a famous FORTRAN code snippet:
>
> 10 STOP
> STOP
> STOP
> ! IN CASE STILL SKIDDING
> GOTO 10


you can laugh about it but I actually have had to write code like
this in interactive applications ( I guess you could laugh at me too LOL)
and sometimes you need it but sometimes it makes things worse. Of course,
normally you would use something like a try/catch for exceptional
conditions but even her it is not always easy to remember to 
close all the resources and in multithreaded code it becomes
even more complex ( there used to be a way in java to stop a thread
but this was removed due to it being inherently unsafe.). 

I've run into this with ctrl-C, my sacred stop all seems to kill R and
leave R term or something so cygwin ends up sending some commands
to bash and some to R until I kill Rterm in task manager. I always
assume I have ctrl-C in my script based data analysis as you really
can't always know how long you want things to go in with exploratory
work ( put ctrl-C in a prespecified analysis plan and see how that goes
over LOL). 



>
>
>
> 
> From: Marius Hofert 
> Date: Sat, 15 Jan 2011 09:09:20 +0100
>
>
> Dear expeRts,
>
> is there a neat way to *completely* stop a script after an error
> occured? For example, consider the following script:
>
> ##  file.R 
>
> for(i in 1:10){
>
> print(i)
> if(i == 5) stop("i == 5")
>
>
> }
> for(i in 11:100) print(i)
>
> ## 
>
>
> stop() behaves like it should namely to stop the execution of the
> *current* expression, but I was wondering if it is possible to *really*
> stop the script after the first for loop [so without executing the
> second for loop or anything after that point]. Of course one could use
> something like "if(there was an error) do not continue" but that's not
> really nice.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Fortune! (Was: How to *completely* stop a script after stop()?)

2011-01-15 Thread Dirk Eddelbuettel

On 15 January 2011 at 11:29, Carl Witthoft wrote:
| 
| Somehow this reminds me of a famous FORTRAN code snippet:
| 
| 10 STOP
| STOP
| STOP
| ! IN CASE STILL SKIDDING
| GOTO 10
 
Immediate candidate for the fortunes package! 

Dirk
 
| 
| From: Marius Hofert 
| Date: Sat, 15 Jan 2011 09:09:20 +0100
| 
| 
| Dear expeRts,
| 
| is there a neat way to *completely* stop a script after an error 
| occured? For example, consider the following script:
| 
| ##  file.R 
| 
| for(i in 1:10){
| 
|   print(i)
|   if(i == 5) stop("i == 5")
| 
| 
| }
| for(i in 11:100) print(i)
| 
| ## 
| 
| 
| stop() behaves like it should namely to stop the execution of the 
| *current* expression, but I was wondering if it is possible to *really* 
| stop the script after the first for loop [so without executing the 
| second for loop or anything after that point]. Of course one could use 
| something like "if(there was an error) do not continue" but that's not 
| really nice.
| 
| __
| R-help@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to *completely* stop a script after stop()?

2011-01-15 Thread Ista Zahn
Hi Carl,
If you wrap the whole script in brackets the script will not proceed
past the stop() function:

{
for(i in 1:10){

   print(i)
   if(i == 5) stop("i == 5")


}
for(i in 11:100) print(i)
}

best,
Ista

On Sat, Jan 15, 2011 at 4:29 PM, Carl Witthoft  wrote:
>
> Somehow this reminds me of a famous FORTRAN code snippet:
>
> 10 STOP
> STOP
> STOP
> ! IN CASE STILL SKIDDING
> GOTO 10
>
>
>
> 
> From: Marius Hofert 
> Date: Sat, 15 Jan 2011 09:09:20 +0100
>
>
> Dear expeRts,
>
> is there a neat way to *completely* stop a script after an error occured?
> For example, consider the following script:
>
> ##  file.R 
>
> for(i in 1:10){
>
>        print(i)
>        if(i == 5) stop("i == 5")
>
>
> }
> for(i in 11:100) print(i)
>
> ## 
>
>
> stop() behaves like it should namely to stop the execution of the *current*
> expression, but I was wondering if it is possible to *really* stop the
> script after the first for loop [so without executing the second for loop or
> anything after that point]. Of course one could use something like "if(there
> was an error) do not continue" but that's not really nice.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to *completely* stop a script after stop()?

2011-01-15 Thread Phil Spector

Marius -
   Do you get the behaviour you want if you substitute

if(i == 5){cat('i==5\n');quit(save='n')}

for the line with the call to stop?


- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sat, 15 Jan 2011, Marius Hofert wrote:


Dear expeRts,

is there a neat way to *completely* stop a script after an error occured?
For example, consider the following script:

##  file.R 

for(i in 1:10){
print(i)
if(i == 5) stop("i == 5")
}
for(i in 11:100) print(i)

## 

stop() behaves like it should namely to stop the execution of the *current*
expression, but I was wondering if it is possible to *really* stop the script 
after
the first for loop [so without executing the second for loop or anything after 
that
point]. Of course one could use something like "if(there was an error) do not 
continue"
but that's not really nice.

Cheers,

Marius
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to *completely* stop a script after stop()?

2011-01-15 Thread Uwe Ligges



On 15.01.2011 18:17, Ista Zahn wrote:

Hi Carl,
If you wrap the whole script in brackets the script will not proceed
past the stop() function:

{
for(i in 1:10){

print(i)
if(i == 5) stop("i == 5")


}
for(i in 11:100) print(i)
}



Yes, or write it inside a function (since I assumed that, I did not even 
understand this question at first) ...


Uwe Ligges



best,
Ista

On Sat, Jan 15, 2011 at 4:29 PM, Carl Witthoft  wrote:


Somehow this reminds me of a famous FORTRAN code snippet:

10 STOP
STOP
STOP
! IN CASE STILL SKIDDING
GOTO 10




From: Marius Hofert
Date: Sat, 15 Jan 2011 09:09:20 +0100


Dear expeRts,

is there a neat way to *completely* stop a script after an error occured?
For example, consider the following script:

##  file.R 

for(i in 1:10){

print(i)
if(i == 5) stop("i == 5")


}
for(i in 11:100) print(i)

## 


stop() behaves like it should namely to stop the execution of the *current*
expression, but I was wondering if it is possible to *really* stop the
script after the first for loop [so without executing the second for loop or
anything after that point]. Of course one could use something like "if(there
was an error) do not continue" but that's not really nice.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.







__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] median by geometric mean

2011-01-15 Thread Skull Crossbones
Hi All,

I need to calculate the median for even number of data points.However
instead of calculating
the arithmetic mean of the two middle values,I need to calculate their
geometric mean.

Though I can code this in R, possibly in a few lines, but wondering if there
is
already some built in function.

Can somebody give a hint?

Thanks in advance

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] color palette for heatmap?

2011-01-15 Thread BD

Hi,

Does anyone know how I can specify the colors based on the data values in
heatmap?
I have values ranging from -4 to 25 and I want to specify colors as:

-4 = white
0 = white/snow
10 =darkblue
20 = red
25 = dark red

the command line that I am currently using is (which is close to what I want
but not exactly)
col=colorRampPalette(c("-5" = "white","5" = "white", "10" = "darkblue", "20"
= "red"))(4)
can I get a smooth transition in heatmap colors from white to blue to red in
R?

Thanks!


-- 
View this message in context: 
http://r.789695.n4.nabble.com/color-palette-for-heatmap-tp3219238p3219238.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] median by geometric mean

2011-01-15 Thread Hadley Wickham
exp(median(log(x)) ?

Hadley

On Sat, Jan 15, 2011 at 10:26 AM, Skull Crossbones
 wrote:
> Hi All,
>
> I need to calculate the median for even number of data points.However
> instead of calculating
> the arithmetic mean of the two middle values,I need to calculate their
> geometric mean.
>
> Though I can code this in R, possibly in a few lines, but wondering if there
> is
> already some built in function.
>
> Can somebody give a hint?
>
> Thanks in advance
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] get list element names within lapply / sapply call

2011-01-15 Thread Jonathan Flowers
Hi all,

I would like to iterate through a list with named elements and access the
names within an lapply / sapply call. One way to do this is iterate through
the names and index the list with the name.  Is there a way to iterate
through the list elements themselves and access the element names within in
the function? For example,

mylist <- list("a"=c(1,2),"b"=c(3,4),"c"=c(5,6))
sapply(mylist,function(x){
  #get name of list elements ("a", "b", "c")
  #then do other stuff
})

Thanks for your suggestions.

Jonathan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to disable using "enter" key to exit the browser in debugging mode

2011-01-15 Thread Gene Leynes
Regarding the issue of "inserting a newline during debugging":

If I remember correctly, this issue didn't happen in older versions of R.
and it seems connected to some other issues.

There generally seems to be something different with how the R Console is
being rendered, and it doesn't seem to be quite as stable.  I'm speaking of
the difference between versions 2.8 (approximately) to 2.11 or 2.12, on
Windows machines with XP and 7.

One piece of evidence is the other issue where the cursor disappears when
running commands, and actually appears somewhere else that doesn't make
sense.  (This has been discussed already in R-Help)

However, I have also noticed weird behavior when
 - working remotely
 - using Eclipse with the StatET plug-in for R
 - when using Tcl\Tk GUI windows

In general, I have been experiencing more instability with the GUI.  It
seems to have more lag or something.

I have also had some system freezes which I think were related to R.  Since
it always happens after I've been remoting into my desktop, and then come
back to work and view the R console.

Sorry this is a little off topic, I just had the newline insertion thing
happen to me (since I wasn't using Eclipse), and I thought I would check
back to see if there was a way to turn it off.

Thanks,

Gene


On Thu, Jan 13, 2011 at 5:20 AM, Prof Brian Ripley wrote:

> You do not mean the "enter" key: it is not that which exits the browser but
> rather a newline (which can be entered via 'return', and in other ways).
>
> This is part of the parser, and there is no way to turn it off.
>
> Somehow other experienced R users have never encountered this.  But if you
> wish you could submit this as a 'wishlist' request to R-bugs, and if enough
> users support it (and especially if someone submits a high-quality patch to
> do this), it might be added in a future release.
>
>
>
> On Wed, 12 Jan 2011, Feng Li wrote:
>
>  Dear R,
>>
>> How can I disable using "enter" key to exit the browser() in debug mode? I
>> would love to have this option because it is so annoying to jump out of
>> the
>> debugging mode unexpectedly when I don't want to. I guess some of us have
>> encouraged at least one of these situations,
>>
>> 1, Accidentally pressed the enter key within the browser.
>>
>> 2, Copy and paste a piece of debugging code containing empty lines to the
>> prompt within the debugging mode.
>>
>> 3, If I paste a piece of code to the prompt to debug as follows, it will
>> eventually jump out before I can do anything.
>>
>> ### copy starting from this line ##
>> test <- function()
>> {
>>x<- 5
>>browser()
>>y<-4
>> }
>>
>> test()
>>
>>  end of copy at this line 
>>
>>
>> Any suggestions are most welcome!
>>
>> Feng
>>
>> --
>> Feng Li
>> Department of Statistics
>> Stockholm University
>> 106 91 Stockholm, Sweden
>> http://feng.li/
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> --
> Brian D. Ripley,  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  
> http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] get list element names within lapply / sapply call

2011-01-15 Thread Gene Leynes
I one tried to write a function to do that, but it wasn't worth it / didn't
work

I found this to be a better solution:
mynames = names(sapply(mylist, names))
for(nm in mynames){
print(mylist[nm])
# or "do other stuff"
}

You can use "browser" to look inside sapply, and the objects available don't
seem to have the current index information, but I don't know how to look at
the ...

> sapply(mylist, browser)
Called from: lapply(X, FUN, ...)
Browse[1]> ls(all.names=TRUE)
[1] "..." "FUN" "X"
Browse[1]> FUN
function (text = "", condition = NULL, expr = TRUE, skipCalls = 0L)
.Primitive("browser")
Browse[1]> X
$a
[1] 1 2

$b
[1] 3 4

$c
[1] 5 6

Browse[1]>


On Sat, Jan 15, 2011 at 3:06 PM, Jonathan Flowers <
jonathanmflow...@gmail.com> wrote:

> Hi all,
>
> I would like to iterate through a list with named elements and access the
> names within an lapply / sapply call. One way to do this is iterate through
> the names and index the list with the name.  Is there a way to iterate
> through the list elements themselves and access the element names within in
> the function? For example,
>
> mylist <- list("a"=c(1,2),"b"=c(3,4),"c"=c(5,6))
> sapply(mylist,function(x){
>  #get name of list elements ("a", "b", "c")
>  #then do other stuff
> })
>
> Thanks for your suggestions.
>
> Jonathan
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] get list element names within lapply / sapply call

2011-01-15 Thread Jonathan Flowers
Thanks Gene.  I'll look into the Browse option.

Best,

Jonathan

On Sat, Jan 15, 2011 at 4:36 PM, Gene Leynes

> wrote:

> I one tried to write a function to do that, but it wasn't worth it / didn't
> work
>
> I found this to be a better solution:
> mynames = names(sapply(mylist, names))
> for(nm in mynames){
> print(mylist[nm])
> # or "do other stuff"
> }
>
> You can use "browser" to look inside sapply, and the objects available
> don't seem to have the current index information, but I don't know how to
> look at the ...
>
> > sapply(mylist, browser)
> Called from: lapply(X, FUN, ...)
> Browse[1]> ls(all.names=TRUE)
> [1] "..." "FUN" "X"
> Browse[1]> FUN
> function (text = "", condition = NULL, expr = TRUE, skipCalls = 0L)
> .Primitive("browser")
> Browse[1]> X
> $a
> [1] 1 2
>
> $b
> [1] 3 4
>
> $c
> [1] 5 6
>
> Browse[1]>
>
>
> On Sat, Jan 15, 2011 at 3:06 PM, Jonathan Flowers <
> jonathanmflow...@gmail.com> wrote:
>
>> Hi all,
>>
>> I would like to iterate through a list with named elements and access the
>> names within an lapply / sapply call. One way to do this is iterate
>> through
>> the names and index the list with the name.  Is there a way to iterate
>> through the list elements themselves and access the element names within
>> in
>> the function? For example,
>>
>> mylist <- list("a"=c(1,2),"b"=c(3,4),"c"=c(5,6))
>> sapply(mylist,function(x){
>>  #get name of list elements ("a", "b", "c")
>>  #then do other stuff
>> })
>>
>> Thanks for your suggestions.
>>
>> Jonathan
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fortune! (Was: How to *completely* stop a script after stop()?)

2011-01-15 Thread Achim Zeileis

On Sat, 15 Jan 2011, Dirk Eddelbuettel wrote:



On 15 January 2011 at 11:29, Carl Witthoft wrote:
|
| Somehow this reminds me of a famous FORTRAN code snippet:
|
| 10 STOP
| STOP
| STOP
| ! IN CASE STILL SKIDDING
| GOTO 10

Immediate candidate for the fortunes package!


Thx, added on R-Forge.
Z


Dirk

| 
| From: Marius Hofert 
| Date: Sat, 15 Jan 2011 09:09:20 +0100
|
|
| Dear expeRts,
|
| is there a neat way to *completely* stop a script after an error
| occured? For example, consider the following script:
|
| ##  file.R 
|
| for(i in 1:10){
|
|   print(i)
|   if(i == 5) stop("i == 5")
|
|
| }
| for(i in 11:100) print(i)
|
| ## 
|
|
| stop() behaves like it should namely to stop the execution of the
| *current* expression, but I was wondering if it is possible to *really*
| stop the script after the first for loop [so without executing the
| second for loop or anything after that point]. Of course one could use
| something like "if(there was an error) do not continue" but that's not
| really nice.
|
| __
| R-help@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

--
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] get list element names within lapply / sapply call

2011-01-15 Thread David Winsemius


On Jan 15, 2011, at 4:06 PM, Jonathan Flowers wrote:


Hi all,

I would like to iterate through a list with named elements and  
access the
names within an lapply / sapply call. One way to do this is iterate  
through

the names and index the list with the name.  Is there a way to iterate
through the list elements themselves and access the element names  
within in

the function? For example,

mylist <- list("a"=c(1,2),"b"=c(3,4),"c"=c(5,6))
sapply(mylist,function(x){
 #get name of list elements ("a", "b", "c")
 #then do other stuff
})


You can pass this result to "[[":
> names(sapply(mylist, names))
[1] "a" "b" "c"

> sapply( names(sapply(mylist, names)) , function(x) mylist[[x]]^2)
 a  b  c
[1,] 1  9 25
[2,] 4 16 36




Thanks for your suggestions.

Jonathan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] get list element names within lapply / sapply call

2011-01-15 Thread David Winsemius


On Jan 15, 2011, at 5:37 PM, David Winsemius wrote:



On Jan 15, 2011, at 4:06 PM, Jonathan Flowers wrote:


Hi all,

I would like to iterate through a list with named elements and  
access the
names within an lapply / sapply call. One way to do this is iterate  
through
the names and index the list with the name.  Is there a way to  
iterate
through the list elements themselves and access the element names  
within in

the function? For example,

mylist <- list("a"=c(1,2),"b"=c(3,4),"c"=c(5,6))
sapply(mylist,function(x){
#get name of list elements ("a", "b", "c")
#then do other stuff
})


You can pass this result to "[[":
> names(sapply(mylist, names))
[1] "a" "b" "c"

> sapply( names(sapply(mylist, names)) , function(x) mylist[[x]]^2)
a  b  c
[1,] 1  9 25
[2,] 4 16 36


Does seem the long way around, though:
> sapply( mylist, function(x) x^2)
 a  b  c
[1,] 1  9 25
[2,] 4 16 36






Thanks for your suggestions.

Jonathan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] (OT) System admin of Rweb at Tama University

2011-01-15 Thread Yihui Xie
Hi,

Sorry to bother all, but recently I found an interesting application
of Rweb (although there are many other fancier web applications of R).
We can submit some simple code to Rweb to create an HTML page
containing animations. Most of Rweb servers I can find are still using
very old versions of R, and the one at Tama University is an exception
(it is using R 2.12.1):

http://data-engine.tama.ac.jp/Rweb/Rweb.general.html

I want to contact the system admin to see if I'm allowed to use their
service, and I also have a few suggestions for them. However, I am
unable to find any contact information on the web page. Google
translate did not help either. Therefore I'm trying the mailing list
in case anybody knows the contact information.

Thanks a lot!

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RSQLite - How to express(or save) a dataframe as an output?

2011-01-15 Thread Michael Bedward
Hi Amelia,

You statement...

dbGetPreparedQuery(con, "INSERT INTO output(df) VALUES (?)", data.frame(output))

...is the problem.

To insert an entire data.frame into the database use dbWriteTable.

To insert with debSendPreparedQuery or dbGetPreparedQuery, the number
of "?" in the VALUES specifier needs to be the same as the number of
fields that you are inserting values into (= the number of cols in
your data.frame).

For example, if you have a table "Foo" with fields Id, Name, Value,
you could do this...

mydf <- data.frame(id=1:3, name=c("foo1", "foo2", "foo3"), value=rnorm(3))
dbGetPreparedQuery(con, "insert into Foo (values (?, ?, ?)", mydf)

which is equivalent to this...
dbGetPreparedQuery(con, "insert into Foo (Id, Name, Value) values (?,
?, ?)", mydf)

Hope that helps,
Michael

On 14 January 2011 18:19, Amelia Vettori  wrote:
> Dear R helpers
>
> Suppose following is an output due to some R process. I wish to save it as a 
> table in 'temp.db'
>
> df <- data.frame(x = c(5, 4, 3, 11), y = c(25, 16, 9, 121))
>
>     library(RSQLite)
>     write('** Initializing','')
>
>     drv <- dbDriver("SQLite", shared.cache = TRUE)
>     con <- dbConnect(drv, dbname = "temp.db",
>  loadable.extensions=TRUE)
>
>     on.exit(dbUnloadDriver(drv))
>     on.exit(dbDisconnect(con))
>
> write('** Save output', '')
>
>  dbBeginTransaction(con)
>
>  dbGetPreparedQuery(con, "INSERT INTO output(df) VALUES (?)", 
> data.frame(output))
>
>  dbCommit(con)
>
>
>>
>  dbGetPreparedQuery(con,
>     "INSERT INTO output(df) VALUES (?)",
>  data.frame(output))
>
>
> # 
> -
>
> I get following message
>
> Error in dbGetPreparedQuery(con, "INSERT INTO output(df) VALUES (?)",  :
>   error in evaluating the argument 'bind.data' in selecting a method for 
> function 'dbGetPreparedQuery'
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.