[ESS] S+ re-factoring ( some recent bugs/annoyances)

gerald.jean at dgag.ca gerald.jean at dgag.ca
Mon Dec 17 16:13:11 CET 2012


Hello Vitalie,

your function now works.  Noticed though that I had to replace all "_" by
".", the "_" is not allowed in Splus it is still reserved, although
obsolete, for assignement.  Here is the output of the function for three
functions, the last one being an home function.

> funnargs(colMeans)
(list "S+" '(("x" . "") ("..." . "")) )

> funnargs(glm)
(list "S+" '(("formula" . "formula(data)") ("family" . "gaussian") ("data"
. "sys.parent()") ("weights" . "") ("subset" . "") ("na.action" . "")
("start" . "eta") ("control" . "glm.control(...)") ("method" .
"\"glm.fit\"") ("model" . "F") ("x" . "F") ("y" . "T") ("contrasts" .
"NULL") ("..." . "")) )

> funnargs(frequence)
(list "S+" '(("object" . "") ("maxsum" . "100") ("sorting" . "F")
("weights" . "NULL")) )

Thanks,

Gérald
                                                                                   
 (Embedded image moved to file:                                                    
 pic14887.gif)                                                                     
                                                                                   
 Gerald Jean, M. Sc. en statistiques                                               
 Conseiller senior en statistiques     Lévis (siège social)                        
                                                                                   
 Actuariat corporatif,                 418 835-4900, poste                         
 Modélisation et Recherche             7639                                        
 Assurance de dommages                 1 877 835-4900, poste                       
 Mouvement Desjardins                  7639                                        
                                       Télécopieur : 418                           
                                       835-6657                                    
                                                                                   


                                                                                  
 Faites bonne impression et imprimez seulement au besoin!                         
                                                                                  
 Ce courriel est confidentiel, peut être protégé par le secret professionnel et   
 est adressé exclusivement au destinataire. Il est strictement interdit à toute   
 autre personne de diffuser, distribuer ou reproduire ce message. Si vous l'avez  
 reçu par erreur, veuillez immédiatement le détruire et aviser l'expéditeur.      
 Merci.                                                                           
                                                                                  




Vitalie Spinu <spinuvit at gmail.com> a écrit sur 2012/12/16 08:27:48 :

>
> Hi again,
>
> Here is a simpler version:
>
>
>   funnargs <-
>     function(object){
>       funname <- deparse(substitute(object))
>       fun <- try(object, silent = TRUE) ## works for special objects also
>       if(is.function(fun)) {
>         special <- grepl('[:$@[]', funname)
>         args <- args(fun)
>         fmls <- formals(args)
>         fmls_names <- names(fmls)
>         fmls <- gsub('\"', '\\\"', as.character(fmls), fixed=TRUE)
>         args_alist <- sprintf("'(%s)", paste("(\"", fmls_names, "\"
> . \"", fmls, "\")", sep = '', collapse = ' '))
>         envname <-  if (special) "" else "S+"
>         cat(sprintf('(list \"%s\" %s )\n', envname, args_alist))
>       }
>     }
>
> This is what it should return:
>
>   R> tl <- list(pl =  plot)
>   R> funnargs(tl$pl)
>   (list "" '(("x" . "") ("y" . "") ("..." . "")) )
>
>
> I have a bunch of comits waiting for someone to confirm that the above
> works in S+.
>
>     Thanks,
>     Vitalie
>
>
>   >> Vitalie Spinu <spinuvit at gmail.com>
>   >> on Thu, 13 Dec 2012 14:45:28 +0100 wrote:
>
>   >> the following functions are unknown to S+:
>
>   >> tryCatch, environmentName, environment
>
>   > So are there packages, directories? Functions are store somewhere.
>
>   > I just need a function that takes an OBJECT and if that OBJECT is a
>   > function, print a string of the form '(list "funPackage" '(("a" .
"4")
>   > ("b" . "5")) )' where funPackage is the location of the function. The
>   > second sub-list is an elisp alist with keys -- the function
arguments,
>   > and the values -- the default values. If that OBJECT is not a
function
>   > return NULL.
>
>   > It should not be difficult,  just to replace tryCatch,
environmentName
>   > and environment with the counterparts in S+ in the code I provided.
Here
>   > it is again:
>
>   >   funnargs <-
>   >     function(object){
>   >       funname <- as.character(substitute(object))
>   >       fun <- tryCatch(object, error=function(e) NULL) ## works
> for special objects also
>   >       if(is.function(fun)) {
>   >         args <- args(fun)
>   >         fmls <- formals(args)
>   >         fmls_names <- names(fmls)
>   >         fmls <- gsub('\"', '\\\"', as.character(fmls), fixed=TRUE)
>   >         args_alist <- sprintf("'(%s)", paste("(\"", fmls_names,
> "\" . \"", fmls, "\")", sep = '', collapse = ' '))
>   >         envname <- environmentName(environment(fun))
>   >         cat(sprintf('(list \"%s\" %s )\n', envname, args_alist))
>   >       }
>   >     }
>
>   > Can you please investigate?
>
>   >> I am going to try to install the SVN version of S+ but I have no
>   >> administrative rights on the machie where I am running Splus,
> will it work
>   >> anyway???
>
>   > Yes it will work in any directory you have write permissions. It is
>   > "make" not "make install" that you have to run. You don't need
>   > administrative rights for that.
>
>   >     Vitalie
>
>   >> (Embedded image moved to file:

>   >> pic19718.gif)

>
>   >> Gerald Jean, M. Sc. en statistiques

>   >> Conseiller senior en statistiques     Lévis (siège social)

>
>   >> Actuariat corporatif,                 418 835-4900, poste

>   >> Modélisation et Recherche             7639

>   >> Assurance de dommages                 1 877 835-4900, poste

>   >> Mouvement Desjardins                  7639

>   >> Télécopieur : 418
>   >> 835-6657
>
>   >> Faites bonne impression et imprimez seulement au besoin!

>
>   >> Ce courriel est confidentiel, peut être protégé par le secret
> professionnel et
>   >> est adressé exclusivement au destinataire. Il est strictement
> interdit à toute
>   >> autre personne de diffuser, distribuer ou reproduire ce
> message. Si vous l'avez
>   >> reçu par erreur, veuillez immédiatement le détruire et aviser
> l'expéditeur.
>   >> Merci.

>
>   >> Vitalie Spinu <spinuvit at gmail.com> a écrit sur 2012/12/12 11:22:45 :
>
>   >> >> gerald.jean at dgag.ca
>   >> >> on Wed, 12 Dec 2012 10:28:58 -0500 wrote:
>   >>
>   >> [...]
>   >>
>   >>
>   gj> I am willing to test this release from SVN but have never installed
>   gj> anything from SVN, where do I find how to do it???
>   >>
>   >> It's very easy. The somewhat obfuscated instructions are
>   >> http://ess.r-project.org/Manual/ess.html#Installation>
>   >> Just do
>   >>
>   >> svn checkout https://svn.r-project.org/ESS/trunk ESS
>   >>
>   >> this creates ESS directory with the source inside. Switch to it and
do
>   >>
>   >> make
>   >>
>   >> This step is not strictly necessary but it makes things faster.
>   >>
>   >> Now add to your init file:
>   >>
>   >> (load "~/path/to/ESS/lisp/ess-site")
>   >>
>   >> That's all.
>   >>
>   >> [...]
>   >>
>   >>
>   >> >> > args("plot")
>   >> >> function (x, y, ...)
>   >> >> NULL
>   >> >> >
>   >>
>   >> Good, now check if this function works:
>   >>
>   >> funnargs <-
>   >> function(object){
>   >> funname <- as.character(substitute(object))
>   >> fun <- tryCatch(object, error=function(e) NULL) ## works for
>   >> special objects also
>   >> if(is.function(fun)) {
>   >> args <- args(fun)
>   >> fmls <- formals(args)
>   >> fmls_names <- names(fmls)
>   >> fmls <- gsub('\"', '\\\"', as.character(fmls), fixed=TRUE)
>   >> args_alist <- sprintf("'(%s)", paste("(\"", fmls_names, "\"
>   >> . \"", fmls, "\")", sep = '', collapse = ' '))
>   >> envname <- environmentName(environment(fun))
>   >> cat(sprintf('(list \"%s\" %s )\n', envname, args_alist))
>   >> }
>   >> }
>   >>
>   >> it should do something of this kind:
>   >>
>   >>
>   >> > funnargs(plot)
>   >> (list "graphics" '(("x" . "") ("y" . "") ("..." . "")) )
>   >> > funnargs(ls)
>   >> (list "base" '(("name" . "") ("pos" . "-1") ("envir" . "as.
>   >> environment(pos)") ("all.names" . "FALSE") ("pattern" . "")) )
>   >>
>   >> If it works, then we are done. You will have your eldoc in the
evening.
>   >>
>   >> Let me know what it returns for local functions:
>   >>
>   >> > tt <- list(fun =  function(a = 4, b = 5) a*b)
>   >> > funnargs(tt$fun)
>   >> (list "R_GlobalEnv" '(("a" . "4") ("b" . "5")) )
>   >>
>   >>
>   >> Vitalie
>


More information about the ESS-help mailing list