[Rd] Detecting typo in function argument

From: John C Nash <nashjc_at_uottawa.ca>
Date: Mon, 12 Dec 2011 16:10:07 -0500


With some chagrin after spending a couple of hours trying to debug a script, I realized I had typed in something like

ans<-optimx(start, myfn, mygr, lower<-lo, upper=up)

that is, the "<-" rather than "=". The outcome on my machine was a non-obvious error several layers deep in the call stack. For info, optim() seems to stop much more quickly.

The error is "obvious", but I'm wondering if there is a simple way to trap or warn of it. For completeness, I include the commands I used to force the error. Note that it will only work fully with the latest (R-forge) version of optimx/optfntools because of the form of gr="gfwd" that allows a choice of different numerical gradient routines.

This is a curiosity rather than a necessity, but if there is a simple way to check, I'll put it in my codes.

Cheers,

JN

rm(list=ls())
start<-rep(3,6)
lo<-rep(2,6)
up<-rep(4,6)
flb <- function(x)

    { p <- length(x); sum(c(1, rep(4, p-1)) * (x - c(1, x[-p])^2)^2) } ans<-optim(start, flb, lower=lo, upper=up) ans
ans<-optim(start, flb, lower<-lo, upper=up) ans
ans1<-optim(start, flb, lower<-lo, upper=up) ans1
require(optimx)

ans1x<-optimx(start, flb, lower<-lo, upper=up) ans1x<-optimx(start, flb, gr="gfwd",lower<-lo, upper=up) ans1<-optim(start, flb, gr=NULL,lower<-lo, upper=up)



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 12 Dec 2011 - 21:14:14 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 13 Dec 2011 - 17:50:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive