Re: [Rd] feature request: optim() iteration of functions that return multiple values

2023-08-05 Thread Martin Becker
For a solution that does not require any change to the original function 
being optimized, the following one-liner could be used, which converts 
existing functions to functions that return only the first element:


returnFirst <- function(fun) function(...) do.call(fun,list(...))[[1]]

Example:

fr <- function(x) {   ## Rosenbrock Banana function
  x1 <- x[1]
  x2 <- x[2]
  ans <- 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
  list(ans=ans, extra1 = 1:10, extra2 = letters)
}

fr2 <- returnFirst(fr)
tmp <- optim(c(-1.2,1), fr2)
fr(tmp$par)


Am 03.08.23 um 22:21 schrieb Sami Tuomivaara:

Dear all,

I have used optim a lot in contexts where it would useful to be able to iterate 
function myfun that, in addition to the primary objective to be minimized 
('minimize.me'), could return other values such as alternative metrics of the 
minimization, informative intermediate values from the calculations, etc.

myfun  <- function()
{
...
return(list(minimize.me = minimize.me, R2 = R2, pval = pval, etc.))
}

During the iteration, optim could utilize just the first value from the myfun 
return list; all the other values calculated and returned by myfun could be 
ignored by optim.
After convergence, the other return values of myfun could be finally extracted and 
appended into the optim return value (which is a list) as additional entry e.g.: 
$aux <- list(R2, pval, etc.), (without 'minimize.me' as it is already returned 
as $value).

The usual ways for accessing optim return values, e.g., $par, $value, etc. are 
not affected.  Computational cost may not be prohibitive either.  Is this 
feasible to consider?


[[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


Re: [Rd] random network disconnects

2023-08-05 Thread Ivan Krylov
В Mon, 31 Jul 2023 16:43:17 +0100
Patrick Burns  пишет:

> At work we are getting lots of issues with 'permission denied' or 
> 'network not found' and so forth when reading and writing between our 
> machines and a file server.  This happens randomly so the following 
> function solves the problem for 'cat' commands

These sound like error codes returned from the operating system, which
R has no choice but forward to the user. (Well, in this case the error
turns out to be transient, but files are unfortunately fraught with
peril with no easy solutions [*].)

Even using system call tracing or setting a symbolic debugger breakpoint
on an error return from cat() will only tell you the OS error code and
the file on which the operation failed, both of which you already know.
Getting to the root of the problem will likely involve drilling down
into the details of the exact networked filesystem used, which R is
supposed to know nothing about. Maybe you could ask on ServerFault or
on #linux / #windows / # on Libera.Char?

-- 
Best regards,
Ivan

[*] https://danluu.com/deconstruct-files/

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


[Rd] HTML documentation check works best with Tidy >= 5.0.0

2023-08-05 Thread Ivan Krylov
Hello R-devel,

Old versions of HTML Tidy report false positive NOTEs for the HTML
verison of the manual where Tidy encounters HTML5 features it is not
ready for.

Conveniently, both HTML5 support and release version numbers officially
appeared in HTML Tidy version 5.0.0 [*]. For example, the last version
of the "old Tidy" I could find fails on an R help page:

 cvs -z3 -d:pserver:anonym...@tidy.cvs.sourceforge.net:/cvsroot/tidy \
  co -P tidy
 cd tidy
 make -C build/gmake
 bin/tidy -v
 # HTML Tidy for Linux released on 25 March 2009
 R-devel CMD Rdconv .../R-devel/src/library/stats/man/lm.Rd -t html | \
  bin/tidy >/dev/null
 # line 4 column 1 - Warning:  inserting "type" attribute
 # line 12 column 1 - Warning: 

[Rd] hist(..., log="y")

2023-08-05 Thread Ott Toomet
Sorry if this topic has been discussed earlier.

Currently, hist(..., log="y") fails with

> hist(rexp(1000, 1), log="y")
Warning messages:
1: In plot.window(xlim, ylim, "", ...) :
  nonfinite axis=2 limits [GScale(-inf,2.59218,..); log=TRUE] -- corrected
now
2: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  "log" is not a graphical parameter
3: In axis(1, ...) : "log" is not a graphical parameter
4: In axis(2, at = yt, ...) : "log" is not a graphical parameter

The same applies for log="x"

> hist(rexp(1000, 1), log="x")
Warning messages:
1: In plot.window(xlim, ylim, "", ...) :
  nonfinite axis=1 limits [GScale(-inf,0.954243,..); log=TRUE] -- corrected
now
2: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  "log" is not a graphical parameter
3: In axis(1, ...) : "log" is not a graphical parameter
4: In axis(2, at = yt, ...) : "log" is not a graphical parameter

This applies for the current svn version of R, and also a few recent
published versions.  This is unfortunate for two reasons:

* the error message is not quite correct--"log" is a graphical parameter,
but "hist" does not support it.
* for various kinds of data it is worthwhile to make histograms in log
scale.  "hist" is a very nice and convenient function and support for log
scale would be handy here.

I also played a little with the code, and it seems to be very easy to
implement.  I am happy to make a  patch if the team thinks it is worth
pursuing.

Cheers,
Ott

[[alternative HTML version deleted]]

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