Re: [Rd] Passing R code from webpage

2013-02-18 Thread Pulkit Mehrotra
hi ,

First of all you should as this question on r-help rather than on r-devel
as this group deals with development related issues with R.

As for the package you can use the shiny package from Rstudio. I have
provided the links below.

http://shiny.rstudio.org/
http://www.rstudio.com/shiny/

regards,
Pulkit

On Sat, Feb 16, 2013 at 3:48 PM, Matevz Pavlic wrote:

> Hi all,
>
> Is there a way to pass R code from web page (html file) to do some
> statistics and than plot the output in web browser.
>
> I am looking forever at this, and cant find a way.
>
> Regards,m
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Mike Marchywka




> Date: Sun, 17 Feb 2013 04:27:38 -0800
> From: mehrotra.pul...@gmail.com
> To: matevzpav...@gmail.com
> CC: r-devel@r-project.org
> Subject: Re: [Rd] Passing R code from webpage
>
> hi ,
>
> First of all you should as this question on r-help rather than on r-devel
> as this group deals with development related issues with R.

Well, personally this potentially a rather substantial issue and while methods
may exist to interface R to webservers, it may be worth discussing if there are
any things you could do to R to make it run more easily as an "R" server
so that you need not make a bunch of instance to run in this setting.
If 10 people on the same machine use R, what duplication is there?
Can I launch a background task within R and still work in foreground?
Is there anything anyone could should or wants to change in R to make this
work better here? 


>
> As for the package you can use the shiny package from Rstudio. I have
> provided the links below.
>
> http://shiny.rstudio.org/
> http://www.rstudio.com/shiny/
>
> regards,
> Pulkit
>
> On Sat, Feb 16, 2013 at 3:48 PM, Matevz Pavlic wrote:
>
> > Hi all,
> >
> > Is there a way to pass R code from web page (html file) to do some
> > statistics and than plot the output in web browser.
> >
> > I am looking forever at this, and cant find a way.
> >
> > Regards,m
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> > Sent from the R devel mailing list archive at Nabble.com.
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
  
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] nobs() with glm(family="poisson")

2013-02-18 Thread Milan Bouchet-Valat
Hi!

The nobs() method for glm objects always returns the number of cases
with non-null weights in the data, which does not correspond to the
number of observations for Poisson regression/log-linear models, i.e.
when family="poisson" or family="quasipoisson".

This sounds dangerous since nobs() is, as the documentation states,
primarily aimed at computing the Bayesian information criterion. Raftery
(1995:20) warned against this:
> What should n be? Once again, it is best to use the actual number of
> individuals, i.e. the sum of the cell counts, and not the number of
> cells (Raftery, 1986a).

Is there a reason why this should not/cannot be done that way?

This behavior can be reproduced with with R 3.0.0 from SVN, using the
example from ?glm:
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
nobs(glm.D93)
# 9 == length(counts)
# Should be 150 == sum(counts)

FWIW, stats:::nobs.glm is currently defined as:
nobs.glm <- function (object, ...) 
if (!is.null(w <- object$prior.weights)) sum(w != 0) else 
length(object$residuals)


Thanks!


Raftery, Adrian E. 1995. “Bayesian Model Selection in Social Research.”
Sociological methodology 25:111–96.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Matevz Pavlic
Hi, 

i think all of this i kinda complicated, even though in all the packages
authors  are saying that "minimum code is required". 
I mean, i am not an IT engineer , but i have created quite some webpages, so
i have some knowledge of HTML5, CSS, C# (limited), and also work quite a lot
with R and still installing R to run as a webserver seems to be too
complicated. 
I have look in all packages i can imaggine, Rook, ggoleVis, Shinybut in
all i get the problem when i want to connect to a MS SQL database.


This is the workflow that i'd like to achieve : 
1.) in webrowser connect to MS SQL database
2.) do some R statistics and plots
3.) show that in web browser.


I am pretty sure it can be very complicated, but it just seems so.

any help (still) greatly appreciated.

BTW: I HAVE posted in R-help, but no responses were given.
m

regards, m



--
View this message in context: 
http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658909.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Mike Marchywka





> Date: Mon, 18 Feb 2013 03:24:43 -0800
> From: matevzpav...@gmail.com
> To: r-devel@r-project.org
> Subject: Re: [Rd] Passing R code from webpage
>
> Hi,
>
> i think all of this i kinda complicated, even though in all the packages
> authors are saying that "minimum code is required".
> I mean, i am not an IT engineer , but i have created quite some webpages, so
> i have some knowledge of HTML5, CSS, C# (limited), and also work quite a lot
> with R and still installing R to run as a webserver seems to be too
> complicated.
> I have look in all packages i can imaggine, Rook, ggoleVis, Shinybut in
> all i get the problem when i want to connect to a MS SQL database.
>
>
> This is the workflow that i'd like to achieve :
> 1.) in webrowser connect to MS SQL database
> 2.) do some R statistics and plots
> 3.) show that in web browser.

Well, if you want a version of R that is a webserver that is one thing,
if you want a webserver that can call R and don't care how it scales then any 
server
that can execute arbitrary executables would work and you could ask on an 
apache list
for example. The problem is getting scaling. In the case we had, results were 
easily cached
and we had a facility for invoking bash scripts and so t the time the R 
instances were not a big
deal. There are several ways, like Rserve, to make R more server like. The case 
we had was mostly loaded
with short requests so we needed to fix the server threading model and used 
netty and java.
You may be happy with apache, no idea. This becomes an issue of R devel if 
anyone things 
there are ways to make multiple R tasks work together better.

Accessing DB from R is probably a help question however :) Although here too 
scaling can be a matter
of caching facilities and a custom server may help there. 




>
>
> I am pretty sure it can be very complicated, but it just seems so.
>
> any help (still) greatly appreciated.
>
> BTW: I HAVE posted in R-help, but no responses were given.
> m
>
> regards, m
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658909.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
  
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Matevz Pavlic
Yes, 

i have looked at apache, but  there is no Windows version (at least to my
knowledge).

I know how to connect to MS SQL from R, i just dont know how to do that from
web browser.

thanks, m



--
View this message in context: 
http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658915.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Mike Marchywka





> Date: Mon, 18 Feb 2013 04:13:25 -0800
> From: matevzpav...@gmail.com
> To: r-devel@r-project.org
> Subject: Re: [Rd] Passing R code from webpage
>
> Yes,
>

y
> knowledge).

well, this getting off topic but I could suggest you go get cygwin and learn to 
use linux
while still on 'dohs LOL I think there is a 'dohs apache version but yes it is 
unlikely
that IIS would interface to stuff like this easily although i have no idea. 


>
> I know how to connect to MS SQL from R, i just dont know how to do that from
> web browser.

If you can do this it is likely a security flaw. You should do all of this on 
the server.
This has nothing to do with R...



>
> thanks, m
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658915.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
  
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Simon Urbanek
On Feb 18, 2013, at 6:24 AM, Matevz Pavlic wrote:

> Hi, 
> 
> i think all of this i kinda complicated, even though in all the packages
> authors  are saying that "minimum code is required". 
> I mean, i am not an IT engineer , but i have created quite some webpages, so
> i have some knowledge of HTML5, CSS, C# (limited), and also work quite a lot
> with R and still installing R to run as a webserver seems to be too
> complicated. 

Not at all - R has a built-in webserver (it's used for the help pages), so if 
you install R, you're done with that part. Rook gives you a wrapper for that.

The problem is it doesn't scale, so if you're happy with one-user solution then 
you can use R without anything. If you need something that scales, then you 
need something else -- and for Windows you're a bit out of luck, because the 
lack of fork+COW on Windows (BTW cygwin doesn't help there, either) paired with 
the fact that R is not thread-safe means it's quite hard to get scalability on 
Windows involving R. The best bet on Windows are server solutions that keep a 
pool of individual R instances as workers but I'm not aware of any off the top 
of my head (I recall some Java solutions way back when Java was hip and I have 
it on my ToDo list for Rserve but it's not there yet).


> I have look in all packages i can imaggine, Rook, ggoleVis, Shinybut in
> all i get the problem when i want to connect to a MS SQL database.
> 

That shouldn't really matter - as long as you can connect from any R session, 
you will be able to connect through R from the webserver.


> This is the workflow that i'd like to achieve : 
> 1.) in webrowser connect to MS SQL database

I assume you mean from the R script? Otherwise you'll have to shove the data 
across (not impossible but why not connect from R?).


> 2.) do some R statistics and plots
> 3.) show that in web browser.
> 
> 
> I am pretty sure it can be very complicated, but it just seems so.
> 
> any help (still) greatly appreciated.
> 
> BTW: I HAVE posted in R-help, but no responses were given.
> m
> 
> regards, m
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658909.html
> Sent from the R devel mailing list archive at Nabble.com.
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Small suggestion for termplot

2013-02-18 Thread Terry Therneau

Brian,
  I used termplot(..., plot=FALSE) recently in R-devel: works like a charm.  Thanks much 
for the update.


  Our in-house "gamterms" function, which this obviates, would also return the "constant" 
attribute from the underlying predict(..., type="terms") call.  I have occasionally found 
this useful, and so it would be a worthwhile addition to termplot.  Currently

  fit <- coxph(Surv(time, status) ~ pspline(age) + sex + ns(wt.loss), 
data=lung)
  zed <- termplot(fit, se=TRUE, plot=FALSE)

returns a list with components zed$age, zed$sex, zed$wt.loss.  The constant could be added 
as another element of the list or as an attribute, I don't have an opinion either way so 
have not suggested a patch.  You may have a reason for preferring one or the other.  
Clearly this is not critical for version 3.0 release.


  I sent this to you since you impliemented the plot=FALSE change, cc to the list in case 
someone else is appropriate.


  For those on the list, the recent change has three nice features:
 a. Use of predict(.., type='terms') is a nuisance because the result is in data set 
order rather than x order, a lines() call becomes a scribble.  This has reduced each term 
to the set of unique x values, in order, just what you need for a plot.
 b. In the coxph example above I use plot(zed$age$x, exp(zed$age$y), log='y') to get 
a better y-axis label.  For all the developers, this is a nice way to deflect requests for 
yet-another-plotting-option addition to termplot.

c. Easy to overlay results from two separate fits.

Terry T.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Hadley Wickham
No one yet has mentioned shiny (http://www.rstudio.com/shiny/); it
allows you to get up and prototyping quickly, and we're working on
ways to make it just as easy to scale to multiple users (currently
it's possible, but you have to be willing to get your hands dirty
configuring servers etc).

Hadley

On Sat, Feb 16, 2013 at 5:48 PM, Matevz Pavlic  wrote:
> Hi all,
>
> Is there a way to pass R code from web page (html file) to do some
> statistics and than plot the output in web browser.
>
> I am looking forever at this, and cant find a way.
>
> Regards,m
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Matevz Pavlic
Hi, 


>Not at all - R has a built-in webserver (it's used for the help pages), so
if you install R, you're done with that part. Rook >gives you a wrapper for
that. 

What do you mean by wrapper? 


> The problem is it doesn't scale, so if you're happy with one-user solution
> then you can use R without anything. If you 
> need something that scales, then you need something else -- and for
> Windows you're a bit out of luck, because the lack > of fork+COW on
> Windows (BTW cygwin doesn't help there, either) paired with the fact that
> R is not thread-safe means i
> quite hard to get scalability on Windows involving R. The best bet on
> Windows are server solutions that keep a pool of 
> individual R instances as workers but I'm not aware of any off the top of
> my head (I recall some Java solutions way back
> when Java was hip and I have it on my ToDo list for Rserve but it's not
> there yet). 

What do you mean by scale/scaling? (not an IT engineer). Mainly this would
be used for one-user-at-the-time. So if by scaling you mean multiple user at
the same time, this would not be a problem

> I have look in all packages i can imaggine, Rook, ggoleVis, Shinybut
> in 
> all i get the problem when i want to connect to a MS SQL database. 
> 

> That shouldn't really matter - as long as you can connect from any R
> session, you will be able to connect through R from 
> the webserver. 

The problem is that i don't even know how to start getting data from SQL and
put it to R and get plot back ;)

> This is the workflow that i'd like to achieve : 
> 1.) in webrowser connect to MS SQL database 

> I assume you mean from the R script? Otherwise you'll have to shove the
> data across (not impossible but why not 
> connect from R?).  

Yes, i know how to do it from R script. Don't know how to do this in HTML.

I just need some pointers (or even better example of code) on how to use R
script in HTML.


Thanks, m



--
View this message in context: 
http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658944.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] quote() vs quote(expr=)

2013-02-18 Thread Hadley Wickham
Hi all,

I think there's a small buglet in quote:

str(quote())
# Error in quote() : 0 arguments passed to 'quote' which requires 1
str(quote(expr = ))
# symbol

I bring this up because this seems like the most natural way of
capturing the "missing" symbol with pure R code, compared to
substitute() or bquote() or formals(plot)$x

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Matevz Pavlic
Hi, 


> No one yet has mentioned shiny (http://www.rstudio.com/shiny/); it 
> allows you to get up and prototyping quickly, and we're working on 
> ways to make it just as easy to scale to multiple users (currently 
> it's possible, but you have to be willing to get your hands dirty 
> configuring servers etc). 

They did mention itand i took a look. But as always could set it up. Can
find any useful manual for connection to MS SQL server and getting data from
SQL, doing statistics and showing plots in Browser.

Any pointers are welcome...

regards, m




--
View this message in context: 
http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658946.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread peter dalgaard

On Feb 18, 2013, at 16:20 , Hadley Wickham wrote:

> Hi all,
> 
> I think there's a small buglet in quote:
> 
> str(quote())
> # Error in quote() : 0 arguments passed to 'quote' which requires 1
> str(quote(expr = ))
> # symbol
> 

If there is a bug here, I'd say that it is in str(), revealing the 
implementation of the missing value as the symbol ``, which we otherwise try 
not to disclose to R code, e.g.

> as.symbol("")
Error in as.symbol("") : attempt to use zero-length variable name

There's a difference between passing 0 arguments and passing a missing argument 
and I see nothing particularly wrong with quote(expr=) returning missing. It 
is, for instance, reasonably consistent that

> eval(quote(expr=))
Error in eval(expr, envir, enclos) : argument is missing, with no default

> I bring this up because this seems like the most natural way of
> capturing the "missing" symbol with pure R code, compared to
> substitute() or bquote() or formals(plot)$x

Are you sure you want to do that? I tend to think that it belongs in the "if it 
breaks, you get to keep both pieces" category.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Simon Urbanek

On Feb 18, 2013, at 10:20 AM, Matevz Pavlic wrote:

> Hi, 
> 
> 
>> Not at all - R has a built-in webserver (it's used for the help pages), so
> if you install R, you're done with that part. Rook >gives you a wrapper for
> that. 
> 
> What do you mean by wrapper? 
> 

It defines an API that is easier to use that writing the httpd function (which 
is called by the build-in HTTP server) yourself.


>> The problem is it doesn't scale, so if you're happy with one-user solution
>> then you can use R without anything. If you 
>> need something that scales, then you need something else -- and for
>> Windows you're a bit out of luck, because the lack > of fork+COW on
>> Windows (BTW cygwin doesn't help there, either) paired with the fact that
>> R is not thread-safe means i
>> quite hard to get scalability on Windows involving R. The best bet on
>> Windows are server solutions that keep a pool of 
>> individual R instances as workers but I'm not aware of any off the top of
>> my head (I recall some Java solutions way back
>> when Java was hip and I have it on my ToDo list for Rserve but it's not
>> there yet). 
> 
> What do you mean by scale/scaling? (not an IT engineer). Mainly this would
> be used for one-user-at-the-time. So if by scaling you mean multiple user at
> the same time,

Yes

> this would not be a problem
> 

Ok, you're fine then.


>> I have look in all packages i can imaggine, Rook, ggoleVis, Shinybut
>> in 
>> all i get the problem when i want to connect to a MS SQL database. 
>> 
> 
>> That shouldn't really matter - as long as you can connect from any R
>> session, you will be able to connect through R from 
>> the webserver. 
> 
> The problem is that i don't even know how to start getting data from SQL and
> put it to R and get plot back ;)
> 

Why would you want to pull the data client-side? That is quite cumbersome since 
you have to rely on the client (browser) to be able to connect to the database 
-- I don't think that's easy. It's much easier to just tell R what to query for 
and let R pull the data, plot it and return the plots and results.


>> This is the workflow that i'd like to achieve : 
>> 1.) in webrowser connect to MS SQL database 
> 
>> I assume you mean from the R script? Otherwise you'll have to shove the
>> data across (not impossible but why not 
>> connect from R?).  
> 
> Yes, i know how to do it from R script. Don't know how to do this in HTML.
> 
> I just need some pointers (or even better example of code) on how to use R
> script in HTML.
> 

I'm not sure what you really mean ;) - using R from HTML simply means sending R 
code from the client (browser) to the server and have the server run that code. 
That's easy - you simply issue a request, for example
http://myserver/R?eval=print(1:10)
It is inherently unsafe (anyone can do anything on your server), but in 
principle possible. In the real world you probably don't want to do that 
(unless you don't care about security) - you want to have the R script on the 
server to define what to do and just accept input, which could be a SQL query 
for example (still some security implications but not as bad) or even better 
just arguments that define what to look up.

For example (this is using FastRWeb API but it should illustrate the idea):

foo.R:

run <- function(city, ...) {
  if (missing(city)) return("Sorry, you have to specify a city!")
  db <- dbConnect("myDatabase:...")
  q <- dbSendQuery(db, "SELECT age FROM user WHERE city=?", city)
  age <- fetch(q, n = -1)[[1]]
  dbClearResult(q)
  dbDisconnect(db)
  p <- WebPlot(400, 400)
  hist(age)
  p
}
 
In HTML you can either use a form


City: 



or AJAX into a div
 
Paris


where the req() JS function could look like this (a more complete one is in the 
FastRWeb examples):

function req(what, where) {
  if (!window.ajax) {
   if (window.XMLHttpRequest)
window.ajax = new XMLHttpRequest();
  else if (window.ActiveXObject)
window.ajax = new ActiveXObject("Microsoft.XMLHTTP");
  }
  var ajax= window.ajax;
  ajax.open("GET",what);
  ajax.onreadystatechange = function() {
  if (ajax.readyState == 4) {
if (ajax.status == 200)
  document.getElementById(where).innerHTML = ajax.responseText;
else
  document.getElementById(where).innerHTML = "Sorry, cannot load this 
page ("+ajax.status+" "+window.ajax.statusText+")";
}
  }
  ajax.send(null);
  return false;
}

Either way, you get the idea - you could pass a SQL query instead or use eval() 
in the argument if you want (as I said, that's too insecure for my taste). But 
in all cases you are really running everything server-side.


That said, there is potentially another solution -- I don't know anything about 
CSHTML, but if it can really hook into C# from HTML then you make be able to 
use the C# part to connect to R - there is a C# Rserve client (assuming that 
CSHTML is server-side interpretation). This is theoretical, I don't use Windows 
so I don't know if that is meant to work.

Cheers,
Simon

Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread Hadley Wickham
> If there is a bug here, I'd say that it is in str(), revealing the 
> implementation of the missing value as the symbol ``,

Yes, a fix to str would be nice too :)

> which we otherwise try not to disclose to R code, e.g.
>
>> as.symbol("")
> Error in as.symbol("") : attempt to use zero-length variable name


> There's a difference between passing 0 arguments and passing a missing 
> argument and I see nothing particularly wrong with quote(expr=) returning 
> missing. It is, for instance, reasonably consistent that
>
>> eval(quote(expr=))
> Error in eval(expr, envir, enclos) : argument is missing, with no default

quote(expr =) returning missing seems like the right thing to me,
quote() throwing an error does not, because it violates the usual
semantics where f(x = ) is equivalent to f().

>> I bring this up because this seems like the most natural way of
>> capturing the "missing" symbol with pure R code, compared to
>> substitute() or bquote() or formals(plot)$x
>
> Are you sure you want to do that? I tend to think that it belongs in the "if 
> it breaks, you get to keep both pieces" category.

You do occasionally need the missing symbol when computing on the
language (see e.g.
https://github.com/hadley/pryr/blob/master/R/partial.r for an example
of where I use it).  You do have to handle it with care, but you are
limited without it.

I think it's better to have one canonical way of getting the missing
symbol when you need it, so that it's easier to recognise in code, and
to clearly illustrates that you do want the missing symbol.  I'd
certainly accept an argument that there should be a dedicated function
to do this, rather than relying on an implementation side-effect of
quote, bquote etc.

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread peter dalgaard

On Feb 18, 2013, at 17:04 , Hadley Wickham wrote:

> quote(expr =) returning missing seems like the right thing to me,
> quote() throwing an error does not, because it violates the usual
> semantics where f(x = ) is equivalent to f().

Except that it isn't:

> (function(...)nargs())()
[1] 0
> (function(...)nargs())(x=)
[1] 1


-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread luke-tierney

I wouldn't count on any way of capturing this thing being reliable in
the long term.  As I recall what I do in codetools and the compiler is
use features of missing() to test for it, but try to abstract those
uses into one or two places only so I can easily change them if
missing()'s behavior changes. Basically this internal thing
_shouldn't_ be visible at R level, and if we ever figure out how to
make that happen it will.

Best,

luke

On Mon, 18 Feb 2013, Hadley Wickham wrote:


Hi all,

I think there's a small buglet in quote:

str(quote())
# Error in quote() : 0 arguments passed to 'quote' which requires 1
str(quote(expr = ))
# symbol

I bring this up because this seems like the most natural way of
capturing the "missing" symbol with pure R code, compared to
substitute() or bquote() or formals(plot)$x

Hadley




--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread Hadley Wickham
On Mon, Feb 18, 2013 at 10:35 AM, peter dalgaard  wrote:
>
> On Feb 18, 2013, at 17:04 , Hadley Wickham wrote:
>
>> quote(expr =) returning missing seems like the right thing to me,
>> quote() throwing an error does not, because it violates the usual
>> semantics where f(x = ) is equivalent to f().
>
> Except that it isn't:
>
>> (function(...)nargs())()
> [1] 0
>> (function(...)nargs())(x=)
> [1] 1

But hardly any functions use nargs:

> find_funs("package:base", fun_calls, fixed("nargs"))
Using environment package:base
 [1] "-.Date"   "-.POSIXt" "[.data.frame"
 [4] "[[.data.frame""[[<-.data.frame"  "[[<-.numeric_version"
 [7] "[<-.data.frame"   "+.Date"   "+.POSIXt"
[10] "diag" "message"  "Ops.data.frame"
[13] "Ops.Date" "Ops.difftime" "Ops.numeric_version"
[16] "Ops.POSIXt"   "seq.default"  "stop"
[19] "system.file"  "trace""warning"
> find_funs("package:stats", fun_calls, fixed("nargs"))
Using environment package:stats
[1] "model.frame.default"

The majority is used to switch between cases like -x vs x - y or to
detect extra arguments if something weird is being done with ...

So I think it's reasonable to expect that f() and f(x = ) do the same thing.

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread Hadley Wickham
In general, should we expect that the ability to compute on the
language within R will decrease over time? Otherwise, I presume if you
do change the behaviour of missing then you'll still provide some way
to create/call functions with missing arguments.

Hadley

On Mon, Feb 18, 2013 at 12:31 PM,   wrote:
> I wouldn't count on any way of capturing this thing being reliable in
> the long term.  As I recall what I do in codetools and the compiler is
> use features of missing() to test for it, but try to abstract those
> uses into one or two places only so I can easily change them if
> missing()'s behavior changes. Basically this internal thing
> _shouldn't_ be visible at R level, and if we ever figure out how to
> make that happen it will.
>
> Best,
>
> luke
>
>
> On Mon, 18 Feb 2013, Hadley Wickham wrote:
>
>> Hi all,
>>
>> I think there's a small buglet in quote:
>>
>> str(quote())
>> # Error in quote() : 0 arguments passed to 'quote' which requires 1
>> str(quote(expr = ))
>> # symbol
>>
>> I bring this up because this seems like the most natural way of
>> capturing the "missing" symbol with pure R code, compared to
>> substitute() or bquote() or formals(plot)$x
>>
>> Hadley
>>
>>
>
> --
> Luke Tierney
> Chair, Statistics and Actuarial Science
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa  Phone: 319-335-3386
> Department of Statistics andFax:   319-335-3017
>Actuarial Science
> 241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
> Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu



-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread luke-tierney

Of course not. What I hope can happpen is that we can reduce the
degree to which internal implementation quirks leak out into the user
level. The fact that there is an internal "missing token" (that
happens to be used for a couple of different things) is a quirk; if
you look at the code I use you can see why it is a quirk. Cleaning
this up will help computing on the language (at least that is the
hope).

luke

On Mon, 18 Feb 2013, Hadley Wickham wrote:


In general, should we expect that the ability to compute on the
language within R will decrease over time? Otherwise, I presume if you
do change the behaviour of missing then you'll still provide some way
to create/call functions with missing arguments.

Hadley

On Mon, Feb 18, 2013 at 12:31 PM,   wrote:

I wouldn't count on any way of capturing this thing being reliable in
the long term.  As I recall what I do in codetools and the compiler is
use features of missing() to test for it, but try to abstract those
uses into one or two places only so I can easily change them if
missing()'s behavior changes. Basically this internal thing
_shouldn't_ be visible at R level, and if we ever figure out how to
make that happen it will.

Best,

luke


On Mon, 18 Feb 2013, Hadley Wickham wrote:


Hi all,

I think there's a small buglet in quote:

str(quote())
# Error in quote() : 0 arguments passed to 'quote' which requires 1
str(quote(expr = ))
# symbol

I bring this up because this seems like the most natural way of
capturing the "missing" symbol with pure R code, compared to
substitute() or bquote() or formals(plot)$x

Hadley




--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu







--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] quote() vs quote(expr=)

2013-02-18 Thread Hadley Wickham
Ok, that's what I thought.  Thanks!
Hadley

On Mon, Feb 18, 2013 at 12:43 PM,   wrote:
> Of course not. What I hope can happpen is that we can reduce the
> degree to which internal implementation quirks leak out into the user
> level. The fact that there is an internal "missing token" (that
> happens to be used for a couple of different things) is a quirk; if
> you look at the code I use you can see why it is a quirk. Cleaning
> this up will help computing on the language (at least that is the
> hope).
>
>
> luke
>
> On Mon, 18 Feb 2013, Hadley Wickham wrote:
>
>> In general, should we expect that the ability to compute on the
>> language within R will decrease over time? Otherwise, I presume if you
>> do change the behaviour of missing then you'll still provide some way
>> to create/call functions with missing arguments.
>>
>> Hadley
>>
>> On Mon, Feb 18, 2013 at 12:31 PM,   wrote:
>>>
>>> I wouldn't count on any way of capturing this thing being reliable in
>>> the long term.  As I recall what I do in codetools and the compiler is
>>> use features of missing() to test for it, but try to abstract those
>>> uses into one or two places only so I can easily change them if
>>> missing()'s behavior changes. Basically this internal thing
>>> _shouldn't_ be visible at R level, and if we ever figure out how to
>>> make that happen it will.
>>>
>>> Best,
>>>
>>> luke
>>>
>>>
>>> On Mon, 18 Feb 2013, Hadley Wickham wrote:
>>>
 Hi all,

 I think there's a small buglet in quote:

 str(quote())
 # Error in quote() : 0 arguments passed to 'quote' which requires 1
 str(quote(expr = ))
 # symbol

 I bring this up because this seems like the most natural way of
 capturing the "missing" symbol with pure R code, compared to
 substitute() or bquote() or formals(plot)$x

 Hadley


>>>
>>> --
>>> Luke Tierney
>>> Chair, Statistics and Actuarial Science
>>> Ralph E. Wareham Professor of Mathematical Sciences
>>> University of Iowa  Phone: 319-335-3386
>>> Department of Statistics andFax:   319-335-3017
>>>Actuarial Science
>>> 241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
>>> Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
>>
>>
>>
>>
>>
>
> --
> Luke Tierney
> Chair, Statistics and Actuarial Science
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa  Phone: 319-335-3386
> Department of Statistics andFax:   319-335-3017
>Actuarial Science
> 241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
> Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu



-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Passing R code from webpage

2013-02-18 Thread Matevz Pavlic
*Hi, 

first of all-thank you for your extensive answer.*




> Hi, 
> 
> 
>> Not at all - R has a built-in webserver (it's used for the help pages),
>> so
> if you install R, you're done with that part. Rook >gives you a wrapper
> for
> that. 
> 
> What do you mean by wrapper? 
> 

>It defines an API that is easier to use that writing the httpd function
(which is called by the build-in HTTP server) yourself.

*OK. Thanks for the clarification.*

> What do you mean by scale/scaling? (not an IT engineer). Mainly this would
> be used for one-user-at-the-time. So if by scaling you mean multiple user
> at
> the same time,



I'm not sure what you really mean ;) - using R from HTML simply means
sending R code from the client (browser) to the server and have the server
run that code. That's easy - you simply issue a request, for example
http://myserver/R?eval=print(1:10)

* I don't know if it should work, but he link with example doesn't work on
my machine )*

> For example (this is using FastRWeb API but it should illustrate the
> idea):

*Ok, here's where i lose it.*
/
foo.R:

run <- function(city, ...) {
  if (missing(city)) return("Sorry, you have to specify a city!")
  db <- dbConnect("myDatabase:...")
  q <- dbSendQuery(db, "SELECT age FROM user WHERE city=?", city)
  age <- fetch(q, n = -1)[[1]]
  dbClearResult(q)
  dbDisconnect(db)
  p <- WebPlot(400, 400)
  hist(age)
  p
}/

*Ok, creating a foo.R is easy. But where do i put this file? Do i have to
start the server before or open  R ? *

 
I/n HTML you can either use a form/

/
City: 

/

*How does HTML know where to "look" for the file foo.R. This is what i can
't see written anywhere in manuals?
*
/
Either way, you get the idea - you could pass a SQL query instead or use
eval() in the argument if you want (as I said, that's too insecure for my
taste). But in all cases you are really running everything server-side.
/

*Ok, this is even better. *

/That said, there is potentially another solution -- I don't know anything
about CSHTML, but if it can really hook into C# from HTML then you make be
able to use the C# part to connect to R - there is a C# Rserve client
(assuming that CSHTML is server-side interpretation). This is theoretical, I
don't use Windows so I don't know if that is meant to work./

*Ok, i'll look at it. *

Thank again, 

matevz
>



--
View this message in context: 
http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658988.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Including modified R source code in a package

2013-02-18 Thread Hadley Wickham
Hi all,

I would like to include a function that I have made by modifying an
existing R function (bw.SJ and corresponding code in bandwidths.c).
The header of bandwidths.c states:

/*
 *  R : A Computer Language for Statistical Data Analysis
 *  bandwidth.c by W. N. Venables and B. D. Ripley  Copyright (C) 1994-2001
 *  Copyright (C) 2012  The R Core Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 ...
*/

so it was originally written by Bill Venables and Brian Ripley, who in
2012 passed the copyrights to the R core team.

What do I need to do to ensure meet my obligations under the GPL and
to adequately acknowledge the work of the original authors.
Currently:

* my package has a compatible license (also GPL >= 2), and

* I have acknowledged the authors in the documentation for my function

* In the code, I have retained the copyrights of the original authors

Do I also need to include Brian, Bill or the R core team in the
authors@R field in my DESCRIPTION (as contributors)?

Is there anything else I should do?

Thanks!

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] best way to extract this meaningful data from a table

2013-02-18 Thread bryan rasmussen
I have a table with a structure like the following:

lang | basic id | doc id | topics|
se  | 447157 | MD_2002_0014 |12 |

loaded topics <- read.table("path to file",header=TRUE, sep="|",
fileEncoding="utf-8")

In that table the actual meaningful data (in this context) is the text
before the first underscore in doc id which is the document type ( for
example MD as above), and topics.
However topics can have more than one value in it, multiple values are
comma separated, if there is no actual topic I have a 0 although I can
also have an empty column if I want.

So what I want is the best way to extract the meaningful data - the
comma separated values of each topics column and the actual document
type so that I can start to do reports of how many documents of type X
have no topics, median number of topics per document type etc.

Do I have to loop through the table and build a new table up with the
info I want, or is there a smarter way to do it?
If a smarter way, what is that smarter way.

Thanks,
Bryan Rasmussen

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] best way to extract this meaningful data from a table

2013-02-18 Thread Kasper Daniel Hansen
This is not an R-devel question, so please do not reply to this list.

I would try
  sapply(strsplit(loaded.topics$doc.id, "_"), function(xx) xx[1])
to get the MD part.

Kasper

On Mon, Feb 18, 2013 at 7:19 PM, bryan rasmussen
 wrote:
> I have a table with a structure like the following:
>
> lang | basic id | doc id | topics|
> se  | 447157 | MD_2002_0014 |12 |
>
> loaded topics <- read.table("path to file",header=TRUE, sep="|",
> fileEncoding="utf-8")
>
> In that table the actual meaningful data (in this context) is the text
> before the first underscore in doc id which is the document type ( for
> example MD as above), and topics.
> However topics can have more than one value in it, multiple values are
> comma separated, if there is no actual topic I have a 0 although I can
> also have an empty column if I want.
>
> So what I want is the best way to extract the meaningful data - the
> comma separated values of each topics column and the actual document
> type so that I can start to do reports of how many documents of type X
> have no topics, median number of topics per document type etc.
>
> Do I have to loop through the table and build a new table up with the
> info I want, or is there a smarter way to do it?
> If a smarter way, what is that smarter way.
>
> Thanks,
> Bryan Rasmussen
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel