On Tue, 7 Jul 2009, Riccardo (Jack) Lucchetti wrote:
On Tue, 7 Jul 2009, Allin Cottrell wrote:
> I think it's clear that we need to take some time to get this
> right. I propose to leave Rlib interaction as a "hidden",
> experts-only, thing in 1.8.2 (and I won't yet attempt to add it to
> the Windows build). We can figure out the details for 1.8.3.
Agreed!
Still all hidden, but I've just added a couple of things
provisionally.
* A "set" variable named "R_functions". Unless this is set
"on"
gretl will not attempt to look up R functions. (This doesn't
affect the existing "foreign" machanisms.) I didn't call the
variable "R_support" because that seemed too general: some level
of R support is on by default and I don't suppose we want to
change that.
* Provisional namespace "R_*" for R function lookup. I agree with
Sven that "R." might be nicer syntax but that would be harder to
implement given our current use of "."; this is just quick and
dirty for now.
The above applies to both built-in R functions such as "choose"
and to ad hoc R functions defined via a "foreign" block.
Revised sample scripts:
<script>
set R_functions on
# call R's "choose"
scalar c = R_choose(10,4)
</script>
<script>
# define and call an R function
open data4-1
set R_functions on
matrix y = {price}
matrix x = {sqft}
foreign language=RLib
ols<-function(y,x) {
m <- lm(y~x+1)
b <- as.matrix(coefficients(m))
invisible(b)
}
end foreign
matrix rb = R_ols(y, x)
rb
</script>
Allin