Please do give reproducible example. The code you gave, which you claimed
`works correctly' doesn't:
> SDT.Optim <- function(crit = NULL, Hess = F)
+ {
+ q <- length(par); x <- data
+ if(hasArg(crit))
+ cat("\n Crit present\n")
+ else
+ cat("\n Crit not present\n")
+ }>
> Gauss.Obj <- SDT.Optim(Par0, Freq, crit, T)
Error in SDT.Optim(Par0, Freq, crit, T) : unused argument(s) ( ...)
The reason is that the function definition says SDT.Optim should only accept
two arguments, but is called with four.
Please also provide the error messages (if any), instead of just saying that
it doesn't `work'. Whatever does that mean?
Andy
> From: Siegfried.Macho
>
> Dear R-helpers,
>
> I got the following problem with the function hasArg()
>
> I would like to use the function to check whether the
> argument "crit" is
> present as an argument of the function (here is the
> simplified version of
> the function):
>
> SDT.Optim <- function(crit = NULL, Hess = F)
> {
> q <- length(par); x <- data
> if(hasArg(crit))
> cat("\n Crit present\n")
> else
> cat("\n Crit not present\n")
> }
>
>
> if I call the function:
>
> Gauss.Obj <- SDT.Optim(Par0, Freq, crit, T)
>
> from the command device the function hasArg() works
> correctly. However, if
> I use the same call within a R-file, loaded via the function
> source(), the
> function hasArg() always retuns FALSE.
>
> Q.1: What is the reason of this behavior and how can I change it?
> Q.2: Before using hasArg() I tried to test whether the value
> of crit is
> NULL using the function is.null(crit) This did not work
> either (at least
> with command files). Why not?
> Q.3: What is the best way to check whether crit was transferred as an
> argument to the function (that works with R-files called via
> source())?
>
> Thank you in advance for your help,
> S.M.
>
>
>
>
>
> =============================================> Dr. Siegfried Macho
> Department of Psychology
> University of Fribourg
> Rue de Faucigny 2
> CH-1700 Fribourg
>
> Tel.: +41-26-3007635
> Fax.: +41-26-3009712
> http://www.unifr.ch/psycho/general/macho.htm
> =============================================> [[alternative HTML
version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments,...{{dropped}}