[Rd] Small typo in Sweave.Rnw

2023-12-11 Thread Enrico Schumann
In the first paragraph of Sweave.Rnw
(./src/library/utils/vignettes/Sweave.Rnw), it reads

  for literate programming \cite{fla:Knuth:1984}.

but probably should be

  for literate programming \citep{fla:Knuth:1984}.
^

kind regards
Enrico

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] NOTE or Information?

2023-11-28 Thread Enrico Schumann
On Tue, 28 Nov 2023, Göran Broström writes:

> A thirty-year-old format error in the C code of my
> package eha was finally detected by the latest R-devel,
> thanks to CRAN for that!
>
> However, I also get a message never seen before, when I check the package:
>
> ---
> Attaching package: ‘rlang’
>
> The following object is masked from ‘package:base’:
>
> %||%
> ---
>
> I guess that this is a result of my use of devtools and
> roxygen for writing documentation. Is this a bug in
> rlang and the mask part of the message will go away
> when it is fixed?
>
> Thanks, Göran
>

A `%||%` operator has been added to R-devel, and hence
the warning about masking:


https://github.com/r-devel/r-svn/commit/aa23547f2c5a80752194647c811fa2c1433d43b9



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] 2 Return values for 2 Functions

2023-09-26 Thread Enrico Schumann
On Tue, 26 Sep 2023, Leonard Mada via R-package-devel writes:

> Dear Members,
>
>
> How should the return values be documented, when the
> help page covers 2 related functions:
>
>
> 1.) Variant 1: fails the checks
>
> \value{
> \code{cryst1} returns a list of class \sQuote{cryst1} with the
> following components:
> \describe{
> \item{abc}{a numeric vector of length 3 containing the norms of the lattice
>   vectors a, b and c there are more items}
> }
> \item{}{}
> \code{is.cryst1} returns TRUE if \code{x} is an object
> of class \sQuote{cryst1}
>   and FALSE otherwise.
> }
>
>
> 2.) Variant 2: fails in Latex
>
> \value{
> \code{cryst1} returns a list of class \sQuote{cryst1} with the
> following components:
> \describe{
> \item{abc}{a numeric vector of length 3 containing the norms of the lattice
>   vectors a, b and c there are more items}
> }
> \cr\cr
> \code{is.cryst1} returns TRUE if \code{x} is an object
> of class \sQuote{cryst1}
>   and FALSE otherwise.
> }
>
>
> 3.) 2 separate Value-Sections
>
> Did not generate actually 2 sections: only the 1st one.
>
>
> Sincerely,
>
>
> Leonard


Have you tried something like this?

\value{
  Function \code{xx} evaluates to a list:
  \item{A}{result A}
  \item{B}{result B}

  Function \code{yy} evaluates to a list:
  \item{C}{result C}
  \item{D}{result D}  
}

"Writing R Extensions" says not to use \describe environments;
see https://cran.r-project.org/doc/manuals/R-exts.html#index-_005cvalue :

,
| Note that \value is implicitly a \describe environment, so
| that environment should not be used for listing components,
| just individual \item{}{} entries.
`



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


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

2023-08-04 Thread Enrico Schumann
On Thu, 03 Aug 2023, Sami Tuomivaara writes:

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

If you only wish to store additional information, you could do
so with an environment, without changing optim.  For instance,
like so (using the first example from ?optim):

data <- new.env()
data$i <- 0
data$fun.value <- numeric(1000)

fr <- function(x, data) {   ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
ans <- 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
data$i <- data$i + 1
data$fun.value[data$i] <- ans
ans
}
optim(c(-1.2,1), fr, data = data)
## $par
## [1] 1.000260 1.000506
## 
## $value
## [1] 8.825241e-08
## 
## $counts
## function gradient 
    ##  195   NA 
## 
## 

data$i
## 195

plot(data$fun.value[1:data$i])




-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] Warning 'as.data.frame.POSIXct()' is deprecated

2023-07-06 Thread Enrico Schumann
On Thu, 06 Jul 2023, Vincent van Hees writes:

> Thanks, in that case the REPLEX for the issue may need to be:
>
>> remember = Sys.getenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_")
>> Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
>> data.frame(time = Sys.time())
>  time
> 1 2023-07-06 14:29:37
>> data.frame(time = as.POSIXlt(Sys.time()))
>  time
> 1 2023-07-06 14:29:37
> Warning message:
> Direct call of 'as.data.frame.POSIXct()' is deprecated.  Use
> 'as.data.frame.vector()' or 'as.data.frame()' instead
>> Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = remember)


I think it happens because

data.frame()

calls 'as.data.frame.POSIXlt' (per its S3-class), which
in turn directly calls 'as.data.frame.POSIXct':

## as.data.frame.POSIXlt
function (x, row.names = NULL, optional = FALSE, ...) 
{
value <- as.data.frame.POSIXct(as.POSIXct(x), row.names, 
optional, ...)
if (!optional) 
names(value) <- deparse1(substitute(x))
value
}


Kind regards
Enrico

> Vincent
>
> On Thu, 6 Jul 2023 at 10:41, Tim Taylor 
> wrote:
>
>> Apologies - I've not had enough caffeine just yet. The reprex below
>> highlights the issue but I think the code which implemented the change
>> *may* need tweaking not lapply.
>>
>> Tim
>>
>> On 06/07/2023 09:26, Tim Taylor wrote:
>> > This *may* be an issue in lapply.  Let's see what others day. Reprex
>> > below
>> >
>> > Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
>> > dat <- Sys.Date()
>> > as.data.frame(dat)
>> > #>  dat
>> > #> 1 2023-07-06
>> > lapply(dat, as.data.frame)
>> > #> Warning: Direct call of 'as.data.frame.Date()' is deprecated.  Use
>> > #> 'as.data.frame.vector()' or 'as.data.frame()' instead
>> > #> [[1]]
>> > #>   X[[i]]
>> > #> 1 2023-07-06
>> >
>> > Tim
>> >
>> > On 06/07/2023 08:54, Vincent van Hees wrote:
>> >> Dear all,
>> >>
>> >> I see the following warning in my package test results:
>> >>
>> >> ```
>> >> Warning
>> >> Direct call of 'as.data.frame.POSIXct()' is deprecated.  Use
>> >> 'as.data.frame.vector()' or 'as.data.frame()' instead
>> >> ```
>> >>
>> >> The warning is not always there and I struggle to make it
>> >> reproducible. I
>> >> have encountered it in both Ubuntu 22.04 and in Windows 11, in both R
>> >> 4.3.0
>> >> and 4.3.1, in both RStudio and in an GitHub Actions environment (example
>> >> <https://github.com/wadpac/GGIR/actions/runs/5463862340/jobs/9945096566>).
>>
>> >>
>> >> The warning gives the impression that I am doing something that R no
>> >> longer
>> >> supports. However, I am not using the command as.data.frame.POSIXct()
>> >> anywhere directly in my code.
>> >>
>> >> When I dive into the code where the warnings occur I see patterns like:
>> >>
>> >> ```
>> >> now = Sys.time()
>> >> df = data.frame (time = seq(now, now + 10, by =1),  B  = 1:11)
>> >> ```
>> >>
>> >> (this is a simplification of for example:
>> >>
>> https://github.com/wadpac/GGIR/blob/master/tests/testthat/test_read.myacc.csv.R
>> >>
>> >> )
>> >>
>> >> Does this mean I am discouraged from putting a vector with POSIXct
>> >> values
>> >> in a data.frame?
>> >> If yes, what would be the recommended work around?
>> >>
>> >> I have been trying to find documentation or online discussions about
>> >> this
>> >> warning but no luck so far. I see R NEWS
>> >> <https://cran.r-project.org/doc/manuals/r-release/NEWS.html> mentions
>> >> updates to POSIXct related objects several times in the past year but
>> >> those
>> >> seem to be different issues.
>> >>
>> >> Best,
>> >>
>> >> Vincent
>> >>
>> >> [[alternative HTML version deleted]]
>> >>
>> >> __
>> >> R-package-devel@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>> >
>> > __
>> > R-package-devel@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>
>   [[alternative HTML version deleted]]
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] Good practice for database with utf-8 string in package

2021-09-17 Thread Enrico Schumann
On Fri, 17 Sep 2021, Marc Girondot via R-package-devel writes:

> I have posted this question first to r-h...@r-project.org and Bert Gunter 
> informs me that it was better for this discussion list that I didn't know.
>
> Hello everyone,
>
> I am a little bit stucked on the problem to include a database with
> utf-8 string in a package. When I submit it to CRAN, it reports NOTES
> for several Unix system and I try to find a solution (if it exists) to
> not have these NOTES.
>
> The database has references and some names have non ASCII characters.
>
> * First I don't agree at all with the solution proposed here:
>
> https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Encoding-issues
>
> "First, consider carefully if you really need non-ASCIItext."
>
> If a language has non ASCII characters, it is not just to make the
> writting nicer of more complex, it is because it changes the prononciation.
>
> * Then I try to find solution to not have these NOTES.
>
> For example, here is a reference with utf-8 characters
>
>> DatabaseTSD$Reference[211]
>
> [1] Hernández-Montoya, V., Páez, V.P. & Ceballos, C.P. (2017) Effects of
> temperature on sex determination and embryonic development in the
> red-footed tortoise, Chelonoidis carbonarius. Chelonian Conservation and
> Biology 16, 164-171.
>
> When I convert the characters into unicode, I get indeed only ASCII
> characters. Perfect.
>
>>   iconv(DatabaseTSD$Reference[211], "UTF-8", "ASCII", "Unicode")
>
> [1] "Hernndez-Montoya, V., Pez, V.P. & Ceballos, C.P.
> (2017) Effects of temperature on sex determination and embryonic
> development in the red-footed tortoise, Chelonoidis carbonarius.
> Chelonian Conservation and Biology 16, 164-171."
>
> Then I have no NOTES when I checked the package with database in UNIX...
> but how can I print the reference back with original characters ?
>
> Thanks a lot to point me to best practices to include databases with
> non-ASCII characters and not have NOTES while submitted package to CRAN.
>
> Marc
>

WRE in section 1.1.5 says:

   "Any byte will be allowed in a quoted character string but ‘\u’
escapes should be used for non-ASCII characters. However, non-ASCII
character strings may not be usable in some locales and may display
incorrectly in others."

So you could try to use such escapes, e.g.

stringi::stri_escape_unicode("Hernández-Montoya")
## [1] "Hern\\u00e1ndez-Montoya"


-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [Rd] order of operations

2021-08-27 Thread Enrico Schumann
On Fri, 27 Aug 2021, Gabor Grothendieck writes:

> Are there any guarantees of whether x will equal 1 or 2 after this is run?
>
> (x <- 1) * (x <- 2)
> ## [1] 2
> x
> ## [1] 2

At least the "R Language Definition" [1] says

  "The exponentiation operator ‘^’ and the left
   assignment plus minus operators ‘<- - = <<-’
   group right to left, all other operators group
   left to right.  That is  [...]  1 - 1 - 1 is -1"

which would imply 2.

[1] 
https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Infix-and-prefix-operators

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] speeding up package code/build/test cycle

2021-06-25 Thread Enrico Schumann
On Thu, 24 Jun 2021, Greg Minshall writes:

> hi.
>
> when developing packages, my current work flow is to change the code,
> (re-)build the package, detach/load the package, test (to find the
> N+1'st bug, sigh).
>
> the building step takes tens of seconds.
>
> is there an obvious way to present some code to the R command line and
> have it replace the appropriate function in a given package?
>
> or, are there other things people do to speed up this process?
>
> thanks in advance, Greg
>

I am not sure if it was already mentioned; but if you feel
comfortable with Emacs (I have a hunch you do), then ESS has
functionality that might help:

http://ess.r-project.org/Manual/ess.html#Developing-with-ESS

and in particular

http://ess.r-project.org/Manual/ess.html#Namespaced-Evaluation


-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] CRAN check texi2dvi failure

2021-01-09 Thread Enrico Schumann
On Sat, 09 Jan 2021, Paul Gilbert writes:

> I am trying to debug a problem that is appearing in the
> linux and Solaris checks, but not Windows or Mac
> checks, of my package tsfa as reported at
> https://cran.r-project.org/web/checks/check_results_tsfa.html
>
> The problem is with re-building the vignette
>   ...
>   this is package 'tsfa' version '2014.10-1'
>   ...
>  checking re-building of vignette outputs ... [6s/9s] WARNING
>  Error(s) in re-building vignettes:
>   ...
> Running 'texi2dvi' on 'Guide.tex' failed.
> LaTeX errors:
> ! LaTeX Error: \verb ended by end of line.
>   ...
>
> In responding to the threat of removal I have also
> fixes some long standing warnings about adding imports
> to the NAMESPACE. The new version builds with --as-cran
> giving no errors or warnings with both R-devel on
> win-builder (2021-01-07 r79806) and on my linux machine
> (R 2021-01-08 r79812 on Linux Mint 19.3 Tricia). When I
> submit it to CRAN the Windows build is OK but the same
> error happens at the 'texi2dvi' step in the debian
> vignette re-build.
>
> This seems to happens after an example that correctly
> has a warning message (about Heywood cases). In my
> linux build the the warning happens but the message
> does not appear in the pdf output, so one possibility
> is that the handling of the warning on the CRAN Unix
> check machines fails to produce clean tex or suppress
> output. Another possibility is that my build using
> --as-cran is different from the actual CRAN build
> options. For example, my 00check.log shows
> ...
> * checking package vignettes in ‘inst/doc’ ... OK
> * checking re-building of vignette outputs ... OK
> * checking PDF version of manual ... OK
> * checking for non-standard things in the check directory ... OK
> ...
>
> so I am not sure if it uses texi2dvi. (I haven't used
> dvi myself for a long time.)
>
> I'm not sure how to debug this when I can't reproduce
> the error. Suggestions would be appreciated.
>
> Paul Gilbert
>

When I run R CMD check on my Linux machine [*], I also
do not get an error.  But here is a guess: The error
mentions \verb, and the LaTeX manual says that \verb
should be followed by nonspace character.  But in the
vignette it is followed by a space.  Maybe using \url
in the vignette could fix the error?

kind regards
Enrico



[*] R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.10



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] How to remove rJava from Ecfun when it's not called directly or indirectly

2020-10-11 Thread Enrico Schumann
On Sat, 10 Oct 2020, Spencer Graves writes:

> Hello, All:
>
>
> "R CMD check Ecfun_0.2-4.tar.gz" fails under
> Windows 10 with "Error: package or namespace load
> failed for 'Ecfun': .onLoad failed in loadNamespace()
> for 'rJava'".
>
>
> However, I cannot find where Ecfun calls rJava.  This is in:
>
>
> https://github.com/sbgraves237/Ecfun
>
>   
> I get nothing from "grep 'rJava'" in the
> DESCRIPTION and NAMESPACE files plus in the man and R
> subdirectories.  I ran tools:package_dependencies
> recursively starting with Ecfun until I got all NULLs
> and could not find rJava anywhere.
>
>
> Thanks,
> Spencer Graves
>
>
> 00install.out
>
>
> * installing *source* package 'Ecfun' ...
> ** using staged installation
> ** R
> ** inst
> ** byte-compile and prepare package for lazy loading
> ** help
> *** installing help indices
> ** building package indices
> ** installing vignettes
> ** testing if installed package can be loaded from temporary location
> *** arch - i386
> Error: package or namespace load failed for 'Ecfun':
>  .onLoad failed in loadNamespace() for 'rJava', details:
>   call: inDL(x, as.logical(local), as.logical(now), ...)
>   error: unable to load shared object 'C:/Program
> Files/R/R-4.0.2/library/rJava/libs/i386/rJava.dll':
>   LoadLibrary failure:  %1 is not a valid Win32 application.
>
> Error: loading failed
> Execution halted
> *** arch - x64
> ERROR: loading failed for 'i386'
> * removing 'C:/Users/spenc/Documents/R/Ecfun/Ecfun.Rcheck/Ecfun'
>
>
> 00check.log
>
>
> * using log directory 'C:/Users/spenc/Documents/R/Ecfun/Ecfun.Rcheck'
> * using R version 4.0.2 (2020-06-22)
> * using platform: x86_64-w64-mingw32 (64-bit)
> * using session charset: ISO8859-1
> * checking for file 'Ecfun/DESCRIPTION' ... OK
> * this is package 'Ecfun' version '0.2-4'
> * checking package namespace information ... OK
> * checking package dependencies ... OK
> * checking if this is a source package ... OK
> * checking if there is a namespace ... OK
> * checking for executable files ... OK
> * checking for hidden files and directories ... OK
> * checking for portable file names ... OK
> * checking whether package 'Ecfun' can be installed ... ERROR
> Installation failed.
> See
> 'C:/Users/spenc/Documents/R/Ecfun/Ecfun.Rcheck/00install.out'
> for details.
> * DONE
> Status: 1 ERROR
>

Hello Spencer

Just a wild guess: the CRAN version of your package
does not list 'xlsx'; but your GitHub version does.
Now, 'xlsx' depends on 'rJava'.  So perhaps start there?

As I said, only a wild guess; but maybe it helps.

Kind regards
Enrico

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] R package which creates a directory in the user home dir

2019-10-17 Thread Enrico Schumann



Quoting Sigbert Klinke :


Hi,

I'am developing a package that circumvents the R package size  
limitation for data sets. For this I store the data set in the  
internet (currently GitHub) and download if it is requested.


To avoid unnecessary downloads and internet connections I create a  
directory in the users home directory to store the data there.  
However, this violates the "CRAN Repository Policy" which says


- Packages should not write in the user’s home filespace (including  
clipboards), nor anywhere else on the file system apart from the R  
session’s temporary directory (or during installation in the  
location pointed to by TMPDIR: and such usage should be cleaned up).


Do I have any chance to get the package to CRAN, if I submit it?

Best Sigbert

--
https://hu.berlin/sk
https://hu.berlin/mmstat3



Hi Sigbert,

there are many packages on CRAN that download data from somewhere
for their users.  They simply ask the user (or rather let the
user specify) if and where to store the data.

kind regards
Enrico

--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [Rd] Producing different text formats in R

2019-08-08 Thread Enrico Schumann
>>>>> "Lluís" ==writes:

Lluís> Dear all,
Lluís> I am facing a strange problem with text files formats.

Lluís> I am currently using a C++ code named voro++ 
(http://math.lbl.gov/voro++/). This code accepts text files with four columns:

Lluís>

Lluís> where id is an identification number and x,y,z are the coordinates 
of a point in a 3D space.

Lluís> The input file, name it myfile_cpp.txt, is generated by another C++ 
code written by myself (named quadscheme.cpp). So far, these calculations 
involve no R code and it works just fine.

Lluís> However, now I am trying to replace my C++ code quadscheme.cpp by a 
R function. The four columns (id,x,y,z) are produced in a matrix or Data Frame 
and then saved in a file myfile_r.txt using write.table(). For example using 
the following function:

Lluís> quadscheme <- function(window, ntile) {
Lluís>   # Creates a grid of points in a 3D orthohedron. 
Lluís>   # First point lies at the (mix,miny,miz) corner of the volume and 
the last one at (maxx,maxy,maxz)
Lluís>   # window: vector. Contains the minimum and maximum values of a 3D 
orthohedron
Lluís>   #   window <- c(minx, maxx, miny, maxy, minz, maxz)
Lluís>   # ntile: vector. Number of points per dimension minus one. We 
manually add a extra row of points per dimension
Lluís>   #   ntile <- c(nstepx, nstepy, nstepz)
Lluís>   M <- prod(ntile+1) 
Lluís>   mat <- matrix(NA,M,4)
Lluís>   mat[,1] <- 1:M # id column
  
Lluís>   # step length per dimension
Lluís>   hi <- (window[2] - window[1])/ntile[1]
Lluís>   hj <- (window[4] - window[3])/ntile[2]
Lluís>   hk <- (window[6] - window[5])/ntile[3]
  
Lluís>   c <- 1
Lluís>   for(i in 0:ntile[1]) {
Lluís> x <- i*hi + window[1]
Lluís> for(j in 0:ntile[2]) {
Lluís>   y <- hj*j + window[3]
Lluís>   for(k in 0:ntile[3]) {
Lluís> z <- k*hk + window[5]
Lluís> mat[c,2:4] <- c(x,y,z) # Add a new point to the grid
Lluís> c <- c + 1
Lluís>   }
Lluís> }
Lluís>   }
Lluís>   write.table(mat, file="myfile_r.txt", row.names=FALSE, 
col.names=FALSE)
Lluís> }

Lluís> And then calling:

>> window <- c(18, 43, 171, 196, 95, 102)
>> ntile <- c(100,100,28)
>> quadscheme(window, ntile)

Lluís> I see no difference between both myfile_*.txt files,
Lluís> one is created with C++ and the other one with
Lluís> R. However, function voro++ do not accept the later one
Lluís> (created with R and saved with write.table). I've also
Lluís> noted that voro++ usually accepts R generated files
Lluís> when they are small enough, but it accepts all C++
Lluís> generated files, regardless the size.

Lluís> I know this is more a C++ than a R question, but may be
Lluís> you can help me as well. I suspect that even if both
Lluís> files are *.txt they have some differences that I
Lluís> cannot see. Is there any way in R to produce different
Lluís> kinds of txt files? Like binary instead of text files?
Lluís> Could this be the problem?

Lluís> I attach two identical files, one produced by C++
Lluís> (myfile_cpp.txt) and another one by the previous R
Lluís> function (myfile_r.txt). I attach as well the C++ code
Lluís> used to generate myfile_cpp.txt.

Lluís> Thank you in advance,

Lluís> Lluís Hurtado-Gil

In your R file, scientific notation is used:

R:
  9 26.5 174.5 96.5
  1e+05 26.5 174.5 96.75
  11 26.5 174.5 97

cpp:
  9 26.5 174.5 96.5
  10 26.5 174.5 96.75
  11 26.5 174.5 97

Try setting options(scipen = 20) before you write the
file in R.



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [Rd] install packages with missing pkg argument

2019-07-29 Thread Enrico Schumann
Maybe related to this?

https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17556

>>>>> "Antoine" == Ant F  writes:

Antoine> Dear all,
Antoine> The help for `?install.packages` decribes, in the `pkg` argument
Antoine> description :

>> If this is missing, a listbox of available packages is presented where
Antoine> possible in an interactive R session.

Antoine> In fact running it with a missing argument triggers an error :

Antoine> install.packages()
>> Error in install.packages : argument "pkgs" is missing, with no default

Antoine> What however doesn't trigger an error is callinginstall.packages 
on a zero
Antoine> length character :

Antoine> install.packages(character(0))

Antoine> On my colleague's R 3.5.1 windows installation it shows the 
listbox of
Antoine> available packages, on my 3.6.0 installation it pauses for a 
couple seconds
Antoine> and doesn't do anything.

Antoine> A character vector of length zero is what you get when you compute 
an empty
Antoine> `setdiff` or `intersection`, so it was very surprising to us to see
Antoine> something popup where we were expecting a vector of missing 
packages to be
Antoine> installed (or none if there was no missing package).

Antoine> I believe having the function work as advertised with a proper 
missing
Antoine> argument, and having it do nothing silently when the argument is 
of length
    Antoine> zero, would make more sense.

Antoine> Best regards,

Antoine> Antoine


-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [Rd] A trap for young players with the lapply() function.

2017-03-29 Thread Enrico Schumann
(inline)

On Tue, 28 Mar 2017, Rolf Turner writes:

> On 28/03/17 04:21, Barry Rowlingson wrote:
>> On Mon, Mar 27, 2017 at 1:17 AM, Rolf Turner <r.tur...@auckland.ac.nz> wrote:
>>>
>>> Is there any way to trap/detect the use of an optional argument called
>>> "X" and thereby issue a more perspicuous error message?
>>>
>>> This would be helpful to those users who, like myself, are bears of very
>>> little brain.
>>>
>>> Failing that (it does look impossible)
>>
>> You can get the names of named arguments:
>>
>>  > z = function(x,X){cos(x*X)}
>>  > names(formals(z))
>>  [1] "x" "X"
>
> That doesn't seem to help.  I tried putting a browser inside lapply()
> and looked at formals(FUN).  This gave NULL, because FUN has already
> been taken to be the list argument "x" to which lapply() is being
> applied.

You can get the call, without the arguments being
matched, with `sys.call`. In your call of lapply,
saying `sys.call()` before anything else would give
you


lapply(y, function(x, X) {
cos(x * X)
}, X = 2 * pi)

which would allow you to get at the argument names of
your function.

if ("X" %in% names(sys.call()[[3L]][[2L]]))
   warnings("found 'X'")

But more would be needed: you need to figure out which
argument you actually meant to be FUN. (In the above,
I simply assumed it was the second passed argument.)
That is, you would need to figure out which passed
argument is a function, which is not safe either,
since ... may also contain functions.


>>> might it not be a good idea to
>>> add a warning to the help for lapply(), to the effect that if FUN has an
>>> optional argument named "X" then passing this argument via "..." will
>>> cause this argument to be taken as the first argument to lapply() and
>>> thereby induce an error?
>>
>> Another idea might be to use purrr:map instead, which is quite happy
>> with X in your function:
>>
>>  >  xxx <- purrr::map(y,function(x,X){cos(x*X)},X=2*pi)
>>  > xxx
>> [[1]]
>> [1] 0.08419541
>>
>> [[2]]
>> [1] 0.6346404
>>
>> [[3]]
>> [1] 0.9800506
>>
>> [[4]]
>> [1] 0.8686734
>>
>> [[5]]
>> [1] -0.9220073
>>
>> But don't feed `.x` to your puing cats, or fails silently:
>>
>>  >  xxx <- purrr::map(y,function(x,.x){cos(x*.x)},.x=2*pi)
>>  > xxx
>> [[1]]
>> NULL
>>
>> But who would have a function with `.x` as an argument?
>
> Indeed.  It struck me that a possible workaround would be to change
> the name of the first argument of lapply() from "X" to ".X".  No-one
> would have a function with an argument names ".X" --- at least I
> wouldn't, so this would solve the problem for me.
>
> It seems to me that this change could be made without breaking anything.
> But perhaps I am engaging in my usual PollyAnna-ish optimism! :-)
>
> cheers,
>
> Rolf

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] duplicate function during build

2016-07-27 Thread Enrico Schumann
rly obvious that I should expect
>>>> issues in this case, but not so clear how to detect the source of the
>>>> problem.
>>>>
>>>> Question: Has anyone created a script to catch such duplicate functions
>>>> from different files during build? I think a warning message that there
>>>> are duplicate functions could save some time and effort. Maybe it's
>>>> already there, but I saw no obvious message. In this case, I'm only
>>>> working in R.
>>>>
>>>> I've found build.R in the R tarball, which is where I suspect such a
>>>> check should go, and I'm willing to prepare a patch when I figure out
>>>> how this should be done. However, it seems worth asking if anyone has
>>>> needed to do this before. I've already done some searching, but the
>>>> results seem to pick up quite different posts than I need.
>>>>
>>>> Cheers, JN
>>>>

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R-pkg-devel] relation between vignettes and help files

2016-07-13 Thread Enrico Schumann
On Wed, 13 Jul 2016, "Boylan, Ross" <ross.boy...@ucsf.edu> writes:

> I have two questions, one substantive and one technical, about the
> relation between vignettes and help files.  By "help files" I mean the
> regular .Rd files.
>
> Substantively, to what extent should material be duplicated between
> the help files and the vignette?  For example, my vignette includes
> some output summarizing the analysis.  The output has many different
> kinds of information, and the details about what they mean are in the
> help for the function generating the output.  Any advice on how much
> of that information to put in the vignette?.  The vignette could, of
> course, say to see the help for the function for details.
>
> It seems natural to me to have the information in both places, except
> that doing so invites inconsistencies as the code changes, if not
> immediately.
>
> The leads to the the technical question: is there a way to provide
> links to the help from the vignette?  I'm using Sweave.  And,
> similarly, is there a way to reference the vignettes from the help?
> In particular, it seems natural to reference the vignette from the
> package help.
>
> Thanks.
> Ross Boylan


I think this was discussed very recently on R-help:

https://stat.ethz.ch/pipermail/r-help/2016-June/439867.html


-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [Rd] Problem with build and check

2014-11-12 Thread Enrico Schumann
On Wed, 12 Nov 2014, Therneau, Terry M., Ph.D. thern...@mayo.edu writes:

 I am getting failure of build and check, for an Rd file that has a long 
 argument list.
 Guess diagnosis: a quoted string beyond a certain point in the argument list 
 is fatal.

Another guess: should you not escape the '%'?  That is, write
\%Y-\%m-\%d?  [Untested.]

 Example:  Use the function below, create an Rd file for it with
 prompt().  Move the .Rd file to the man directory (no need to edit it)
 and try building

 dart.control - function(server=c(production, integration, development,
   http),
  out.poll.duration = 5,
  out.poll.increase = 1.1,
  out.poll.max = 30,
  out.poll.timeout = 3600,
  netrc.path,
  netrc.server = ldap,
  rtype = c(xml, json),
  dateformat= %Y-%m-%d) {

 server - match.arg(server)
 server
 }

 I created a package dummy with only this function, and get the following on 
 my Linux box.

 tmt-local2021% R CMD build dummy
 * checking for file ‘dummy/DESCRIPTION’ ... OK
 * preparing ‘dummy’:
 * checking DESCRIPTION meta-information ... OK
 Warning: newline within quoted string at dart.control.Rd:11
 Warning:
 /tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd:46:
 unexpected section header '\value'
 Warning: newline within quoted string at dart.control.Rd:11
 Error in 
 parse_Rd(/tmp/RtmpjPjz9V/Rbuild398d6e382572/dummy/man/dart.control.Rd, :
   Unexpected end of input (in  quoted string opened at dart.control.Rd:88:16)
 Execution halted

 Session info for my version
 sessionInfo()
 R Under development (unstable) (2014-10-30 r66907)
 Platform: i686-pc-linux-gnu (32-bit)

 locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods base


 Terry T.



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


[Rd] minor typo in docs for 'sort'

2013-05-23 Thread Enrico Schumann
Dear all, 

on the help page for '?sort':


  'Method shell uses Shellsort ([...] from Sedgewick (1996))'


but in the references it is Sedgewick (1986). 1986 seems correct:

http://dx.doi.org/10.1016/0196-6774(86)90001-5


Thank you,
Enrico

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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