[Rd] Rd parser throws error for user macros invoked with empty argument

2018-05-14 Thread Georgi Boshnakov
Bug or feature?

I get the following error from parse_Rd() when a user Rd macro (including 
system ones) is invoked with empty argument {},
eg \mymacro{}:

Error in tools::parse_Rd(fn) :
  Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL'

A full example is further below with the system macro \CRANpkg{}. In this 
example it doesn't make sense to use empty argument but the error is not 
specific to this particular macro.

--
Georgi Boshnakov


Create an Rd file containing system macro \CRANpkg{bibtex}, parse_Rd() is ok:

=
fn <- tempfile()
writeLines("\\name{dummyfun}
\\alias{dummyfun}
\\title{Dummy title}
\\description{Dummy description}
\\usage{
dummyfun(x, ...)
}
\\arguments{
  \\item{x}{a value.}
  \\item{\\dots}{further arguments.}
}
\\details{
\\CRANpkg{bibtex}
}
", fn)

> tools::parse_Rd(fn)
...
\details{
\href{{https://CRAN.R-project.org/package=bibtex}{\pkg{bibtex}}}
}



With empty argument - \CRANpkg{} - Rd parser throws error. Of course it is 
silly in this example but I have used it with other user defined  macros where 
it may make sense to have empty argument.


> writeLines("\\name{dummyfun}
\\alias{dummyfun}
\\title{Dummy title}
\\description{Dummy description}
\\usage{
dummyfun(x, ...)
}
\\arguments{
  \\item{x}{a value.}
  \\item{\\dots}{further arguments.}
}
\\details{
\\CRANpkg{}
}
", fn)
> tools::parse_Rd(fn)
Error in tools::parse_Rd(fn) :
  Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL'

[[alternative HTML version deleted]]

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


Re: [Rd] readLines() behaves differently for gzfile connection

2018-05-14 Thread Michael Lawrence
I haven't been able to reproduce the empty lines issue on my Mac or
Linux laptop, but I have yet to try that container.

The warning is because of a SEEK_SET to -1, which apparently is
unsupported by zlib. Maybe the zlib version in that container is
getting confused. I'm not sure why readLines() wants to seek to -1
instead of 0, but it only does that on non-blocking connections. The
compressed file connections are effectively blocking but are marked as
non-blocking. Marking them as blocking removes the warning. I will get
that into devel and release soon. Hopefully that fixes the empty lines
issue also.

Michael

On Thu, May 10, 2018 at 4:21 PM, Ben Heavner  wrote:
> You bet - it's available on github at
> https://github.com/UW-GAC/wgsaparsr/blob/master/tests/testthat/1k_annotation.gz
>
> -Ben
>
> On Thu, May 10, 2018 at 4:17 PM, Michael Lawrence
>  wrote:
>>
>> Would it be possible to get that file or a representative subset of it
>> somewhere so that I can reproduce this?
>>
>> Thanks,
>> Michael
>>
>> On Thu, May 10, 2018 at 3:31 PM, Ben Heavner  wrote:
>> > When I read a .gz file with readLines() in 3.4.3, it returns text (and a
>> > warning). In 3.5.0, it gives a warning, but no text. Is this expected
>> > behavior or a bug?
>> >
>> > 3.4.3:
>> >> source_file = "1k_annotation.gz"
>> >> readfile_con <- gzfile(source_file, "r")
>> >> readLines(readfile_con, n = 5)
>> > [1] "#chr\tpos\tref\talt\t
>> >
>> > 
>> >
>> > Warning message:
>> > In readLines(readfile_con, n = 5) :
>> >   seek on a gzfile connection returned an internal error
>> >
>> >> close(readfile_con)
>> >
>> >> sessionInfo()
>> > R version 3.4.3 (2017-11-30)
>> > Platform: x86_64-apple-darwin15.6.0 (64-bit)
>> > Running under: macOS Sierra 10.12.6
>> >
>> > Matrix products: default
>> > BLAS:
>> >
>> > /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
>> > LAPACK:
>> >
>> > /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
>> >
>> > locale:
>> > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>> >
>> > attached base packages:
>> > [1] stats graphics  grDevices utils datasets  methods   base
>> >
>> > loaded via a namespace (and not attached):
>> > [1] compiler_3.4.3
>> >
>> > -
>> >
>> > 3.5.0:
>> >> source_file = "1k_annotation.gz"
>> >> readfile_con <- gzfile(source_file, "r")
>> >> readLines(readfile_con, n = 5)
>> > [1] "" "" "" "" ""
>> > Warning message:
>> > In readLines(readfile_con, n = 5) :
>> >   seek on a gzfile connection returned an internal error
>> >> close(readfile_con)
>> >> sessionInfo()
>> > R version 3.5.0 (2018-04-23)
>> > Platform: x86_64-pc-linux-gnu (64-bit)
>> > Running under: Debian GNU/Linux 9 (stretch)
>> >
>> > Matrix products: default
>> > BLAS: /usr/lib/openblas-base/libblas.so.3
>> > LAPACK: /usr/lib/libopenblasp-r0.2.19.so
>> >
>> > locale:
>> >  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>> >  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>> >  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=C
>> >  [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
>> >
>> > loaded via a namespace (and not attached):
>> > [1] compiler_3.5.0
>> >
>> > 
>> > (note: I'm running 3.5.0 via the docker rocker/tidyverse:3.5 container,
>> > and
>> > 3.4.3 on my mac desktop machine)
>> >
>> > Thanks!
>> > Ben Heavner
>> >
>> > [[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] access an element with empty name

2018-05-14 Thread Serguei Sokol

Le 14/05/2018 à 15:55, Kurt Hornik a écrit :

Serguei Sokol writes:

Hi,
I came across a case where I cannot access a list element by its empty name.
Minimal example can be constructed as
      x=list("A", 1)
      names(x)=c("a", "")
      x[["a"]]
      #[1]  "A"
      x[[""]]
      #NULL
      x$`a`
      #[1]  "A"
      x$``
      # Error: attempt to use zero-length variable name
      # but we can still access the second element by its index
      x[[2]]
      #[1] 1
To my mind, it should be perfectly legal to access an element by an
empty name as we can have for example
      match("", names(x))
      #[1] 2
Hence a traditional question: is it a bug or feature?

A feature according to the docs: ? Extract says

 Neither empty (‘""’) nor ‘NA’ indices match any names, not even
 empty nor missing names.



Thanks Kurt, I missed that one.

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


Re: [Rd] access an element with empty name

2018-05-14 Thread Kurt Hornik
> Serguei Sokol writes:

> Hi,
> I came across a case where I cannot access a list element by its empty name.
> Minimal example can be constructed as

>      x=list("A", 1)
>      names(x)=c("a", "")
>      x[["a"]]
>      #[1]  "A"
>      x[[""]]
>      #NULL
>      x$`a`
>      #[1]  "A"
>      x$``
>      # Error: attempt to use zero-length variable name
>      # but we can still access the second element by its index
>      x[[2]]
>      #[1] 1

> To my mind, it should be perfectly legal to access an element by an 
> empty name as we can have for example
>      match("", names(x))
>      #[1] 2
> Hence a traditional question: is it a bug or feature?

A feature according to the docs: ? Extract says

Neither empty (‘""’) nor ‘NA’ indices match any names, not even
empty nor missing names. 

-k



> Best,
> Serguei.


>> sessionInfo()
> R version 3.5.0 (2018-04-23)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Mageia 6

> Matrix products: default
> BLAS/LAPACK: /home/opt/OpenBLAS/lib/libopenblas_sandybridge-r0.3.0.dev.so

> locale:
> [1] C

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

> loaded via a namespace (and not attached):
> [1] compiler_3.5.0

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


[Rd] access an element with empty name

2018-05-14 Thread Serguei Sokol

Hi,

I came across a case where I cannot access a list element by its empty name.
Minimal example can be constructed as

    x=list("A", 1)
    names(x)=c("a", "")
    x[["a"]]
    #[1]  "A"
    x[[""]]
    #NULL
    x$`a`
    #[1]  "A"
    x$``
    # Error: attempt to use zero-length variable name
    # but we can still access the second element by its index
    x[[2]]
    #[1] 1

To my mind, it should be perfectly legal to access an element by an 
empty name as we can have for example

    match("", names(x))
    #[1] 2
Hence a traditional question: is it a bug or feature?

Best,
Serguei.


> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Mageia 6

Matrix products: default
BLAS/LAPACK: /home/opt/OpenBLAS/lib/libopenblas_sandybridge-r0.3.0.dev.so

locale:
[1] C

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

loaded via a namespace (and not attached):
[1] compiler_3.5.0

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