Re: [R] wrtiteBin in conjunction with seek : the position in the file is not good when writing

2024-05-21 Thread Ivan Krylov via R-help
В Tue, 21 May 2024 11:29:33 +0200
Laurent Rhelp  пишет:

> pos <- seek(con_in,2,origin="start")
> # We have to repeat the command to return the good amount of read
> # bytes
> print(paste0("pos is not equal to 2, pos = ",pos))

That's because seek() returns the previous position ("before any
move", the one that the help page calls "current"), not the one after
the seek. Fortunately, calling seek(origin = "start") twice with the
same offset doesn't break anything.

> # we are on position 6
> pos <- seek(con_in,0,origin="current")

That's strange. You started at offset 2 and read three bytes. You
should be at offset 5 at this point. For me, seek() returns 5 here, not
6.

> bytes = readBin(con=con_in, what="raw",n = 1)

But after this, we should be on position 6.

> writeBin(  my_string, con=con_in, useBytes = FALSE)

It's described in help(seek) that R maintains two different pointers
for reading and writing a file. You have been reading it, advancing the
read pointer to 6, but the write pointer stayed at offset 0.

Try seek(con_in, seek(con_in, 0, 'current', 'read'), 'start', 'write')
to set the write pointer to the read pointer before issuing writes.
This seems to give me the expected result.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Description of error is untranslated when R_XLEN_T_MAX is exceeded by only 1 element.

2024-05-13 Thread Ivan Krylov via R-help
Dear Ricardo Villalba,

Thank you for spotting this corner case!

В Mon, 13 May 2024 11:37:57 -0300
Ricardo Villalba  пишет:

> I track the messages to be coded here:
> https://github.com/r-devel/r-svn/blob/abe625945c4402cd2bb97b5a64e7469db3e904f0/src/main/altclasses.c#L580
> and here
> https://github.com/r-devel/r-svn/blob/abe625945c4402cd2bb97b5a64e7469db3e904f0/src/main/seq.c#L102

You may have noticed that one of these places lacks the underscore that
R uses as the translation keyword: it's _(string) that looks up the
translation of the string.

Would you like to suggest a patch on r-de...@r-project.org or
https://bugs.r-project.org ?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there some way to customize colours for the View output?

2024-05-13 Thread Ivan Krylov via R-help
В Mon, 13 May 2024 06:08:22 -0400
Duncan Murdoch  пишет:

> The row and column names don't appear to be controllable from that
> menu, they seem (on my machine) to be displayed in the same colour as
> the background of a dialog box, i.e. some kind of gray.  I don't
> think R tries to control that colour, but perhaps some Windows
> setting would change it.

This is entirely correct: the dialog uses the colour returned by
dialog_bg(), which is GetSysColor(COLOR_BTNFACE).

I think it could be a reasonable feature request to use an adjustable
colour for the row and column headers.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] duplicated() on zero-column data frames returns empty

2024-05-12 Thread Ivan Krylov via R-help
(Sorry for only getting back to this more than a month later.)

В Mon, 8 Apr 2024 17:03:00 +
Jorgen Harmse  пишет:

> What is the policy for changing something that is wrong? There is a
> trade-off between breaking old code that worked around a problem and
> breaking new code written by people who make reasonable assumptions.

First of all, quantify the breakage. Does the proposed change break
`make check-devel`? Does it break CRAN and BioConductor? (This one is
hard to measure properly: someone will have to run >2 R CMD checks
times two, for "before the change" and "after the change".) Given a
persuasive case, breaking changes can still be made, but will require a
deprecation period to let the packages adjust.

If you would like to try your hand at developing a patch and make a
case for it at R-devel or the Bugzilla, the resources at
 can be helpful.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R CMD check vs RStudio check

2024-05-10 Thread Ivan Krylov via R-help
В Fri, 10 May 2024 03:46:54 +
"Boylan, Ross"  пишет:

> The devtools::check() documentation mentions it invoke
> pkgbuild::build() and rcmdcheck::rcmdcheck(). Since I'm guessing my
> command line build and check invoked those last 2, or at least
> operated similarly, they seem less likely suspects.

You are correct, it's part of what pkgbuild::build() does:

https://search.r-project.org/CRAN/refmans/pkgbuild/html/build.html#clean_doc

>> DESCRIPTION entries
>>
>> Config/build/clean-inst-doc can be set to FALSE to avoid cleaning
>> up inst/doc when building a source package. Set it to TRUE to force
>> a cleanup. See the clean_doc argument.

(I didn't know that either, just searched their source code for
"inst.*doc".)

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Compilation problems with R4.4.0

2024-05-09 Thread Ivan Krylov via R-help
Glad you got R working!

В Thu, 9 May 2024 12:19:49 +
Simon Andrews  пишет:

> Does this need reporting upstream as a bug in R or lapack?

Maybe in AlmaLinux (and I think RHEL9 too, but that's up to Miguel
Esteva). Best case scenario, they somehow built the reference BLAS and
LAPACK packages with the wrong Fortran compiler version or flags, which
is why gfortran-11 gets a zero instead of the return value from DOUBLE
COMPLEX zdotu(...) and crashes when calling dgesv(...) from
lapack-3.9.0-10.el9.x86_64. Worst case scenario, the zdotu() problem
and the crash have two completely different causes elsewhere.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using intervals() function for nlme model - Statistics Lab ETHZ

2024-05-09 Thread Ivan Krylov via R-help
Just one more thing: when you do find a solution, can you please share
it with us?

I do trust nlraa::boot_nlme() as it's been deliberately written for
nonlinear mixed-effects models, but the fact that intervals() is
inherited from the 'lme' class without any mention of nonlinear models
in the manual worries me. I don't know if it's intended to work with
'nlme' models.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Compilation problems with R4.4.0

2024-05-08 Thread Ivan Krylov via R-help
В Wed, 8 May 2024 16:59:25 +
Simon Andrews  пишет:

> The lapack libraries are:
> 
> $ rpm -qa | grep lapack
> lapack-3.9.0-10.el9.x86_64
> lapack64_-3.9.0-10.el9.x86_64
> lapack64-3.9.0-10.el9.x86_64
> lapack-devel-3.9.0-10.el9.x86_64

Thanks for this information! I figured out I needed to enable the
"PowerTools/CRB" repo, installed lapack-devel from there, and now I get
the same configure output and the same crash: by linking with R's
built-in Rblas but and system-provided LAPACK-3.9.0.

If I configure --without-lapack, i.e. use both Rblas and R-provided
functions from LAPACK up to 3.12.0, the build doesn't crash.

If I try to enable --with-blas=-lblas, here's what happens:

configure:47862: checking whether double complex BLAS can be used
configure:47946: result: no

The test compares the result of the BLAS function zdotu with the
manually computed vector norm for a complex vector [*]. In this case,
the Fortran program thinks that the BLAS returns a zero instead of the
correct answer, thus failing the test and refusing to compile with
system BLAS.

I think that you somehow stumbled upon a Fortran ABI incompatibility
regarding passing complex numbers between the Fortran code compiled
during R build and the BLAS and LAPACK provided in the PowerTools/CRB
repo. I don't know what exactly is the problem, but at least
--without-lapack is an easy workaround without any cost in performance.

In fact, if you install openblas-devel and configure --with-blas (to
replace Rblas with OpenBLAS), the double complex BLAS test will pass,
the build won't crash, and you will get even better performance.

-- 
Best regards,
Ivan

[*] https://stat.ethz.ch/pipermail/r-devel/2024-March/083302.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Compilation problems with R4.4.0

2024-05-08 Thread Ivan Krylov via R-help
В Wed, 8 May 2024 14:25:08 +
Simon Andrews  пишет:

> #8  0x73f87c0b in dgesv (
>  n=12884901891, nrhs=4294967299,
>  a=,
>  lda=12884901891, ipiv=...,
>  b=,
>  ldb=12884901891, info=0
> ) at /usr/src/debug/lapack-3.9.0-10.el9.x86_64/SRC/dgesv.f:167
> #9 0x750b2a17 in La_solve (
>  tolin=, Bin=, A=0x18f2f68
> ) at Lapack.c:1246
> #10 mod_do_lapack (
>  call=, op=, args=,
>  env=
> ) at Lapack.c:1483

It looks like this R build is linked to a LAPACK. I now also notice
LAPACK(generic) in the list of external libraries in your ./configure
output. I've tried to link R to AlmaLinux's builds of reference BLAS
and LAPACK using --with-blas='-l:libblas.so.3'
--with-lapack='-l:liblapack.so.3' (where do I get libblas.so on
AlmaLinux?), but that doesn't crash either.

What does the config.log currently say about your BLAS and LAPACK
situation? It's a number of lines between

configure:47012: checking whether 'struct tm' includes tm_gmtoff

and

configure:48858: checking for iconv.h.

If you'd like to link your R to custom BLAS and LAPACK, try specifying
the necessary linker flags explicitly with --with-blas=-lwhatever,
--with-lapack=-lwhatever. If you're fine with reference BLAS & LAPACK
that come with R, try ./configure --without-blas --without-lapack.
Normally, R's ./configure tries to prevent linking to an external
LAPACK without linking to an external BLAS; I'm not sure how it got you
LAPACK(generic) without BLAS(generic).

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Compilation problems with R4.4.0

2024-05-08 Thread Ivan Krylov via R-help
Dear Simon,

В Wed, 8 May 2024 10:17:41 +
Simon Andrews via R-help  пишет:

> I'm having a strange problem compiling R4.4.0 on an AlmaLinux9 box.

> make[4]: Entering directory '/bi/apps/R/R-4.4.0/src/library/grDevices'
> byte-compiling package 'grDevices'
> 
> *** caught segfault ***
> address 0x18017a8110, cause 'memory not mapped'
> 
> Traceback:
> 1: solve.default(rgb)

Miguel Esteva has recently complained about the same problem on RHEL9,
but didn't provide enough details, nor was I able to reproduce it
myself: https://stat.ethz.ch/pipermail/r-help/2024-May/479288.html

Thanks for letting us know it's reproducible on AlmaLinux and telling
us your compiler version!

Unfortunately, I wasn't able to reproduce the crash, neither with
gcc-toolset-13, nor with the ordinary gcc & gfortran 11.4.1 20231218
(Red Hat 11.4.1-3) from the repository. I see that your compiler version
is slightly different (11.4.1-2). I'm running `podman run -it --rm
almalinux:9`. Would an upgrade help?

Can you run R under the debugger and obtain a backtrace? Something like
the following, in the src/library/grDevices subdirectory:

_R_COMPILE_PKGS_=1 R_COMPILER_SUPPRESS_ALL=1 \
 R_DEFAULT_PACKAGES=NULL LC_ALL=C \
../../../bin/R -d gdb --vanilla --no-echo -e \
 'tools:::makeLazyLoading("grDevices")'

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with creating a PCA graph in a loop

2024-05-08 Thread Ivan Krylov via R-help
В Tue, 7 May 2024 16:57:14 +0200
gavin duley  пишет:

> aes(label=current_rownames,
> colour=wine.data.filt$Treatment
> )

As you've noticed, aes() remembers variables by their name and
environment, not by value:

str(ggplot2::aes(label = foo))
# List of 1
#  $ label: language ~foo # <-- variable name recorded here
   # and here is the environment
#   ..- attr(*, ".Environment")= 
#  - attr(*, "class")= chr "uneval"

One way to get around the problem is to ensure that the variables live
in different environments. Instead of making it a for loop, write a
function that would accept `i` and return a plot instead of assigning
it by name:

makeplot <- function(i) {
  print(i)
  wine.data.filt <- filter(wine.data,Time == i)
  current_rownames <- rownames(wine.data.filt)
  wine.data.filt.pca <- dudi.pca(wine.data.filt[3:11],
 nf=6,
 scannf=F)
  wine.data_quanti_sup <- wine.data.filt[,12, drop = FALSE]
  return(fviz_pca_ind(wine.data.filt.pca,
   # 
  )
}

individs <- lapply(levels(wine.data$Time), makeplot)
individs[[1]]

(In many languages, trying to use a variable as a variable name, while
possible, usually means you need to consider some kind of nested data
structure:
https://perldoc.perl.org/perlfaq7#How-can-I-use-a-variable-as-a-variable-name?
In R, this structure is a list.)

Why does this work? Calling a function creates a new environment every
time. The plots will all refer to the variable named current_rownames,
but the environments will be different:

attr((function() ggplot2::aes(label = foo))()$label, '.Environment')
# 
attr((function() ggplot2::aes(label = foo))()$label, '.Environment')
# 
attr((function() ggplot2::aes(label = foo))()$label, '.Environment')
# 

Alternatively, supply a data= argument to geom_label_repel() and make
your mapping = aes(...) reference variables from the data (which will
be remembered), ignoring the environment (which is only referenced).
Something like the following should work, untested:

geom_label_repel(
 mapping = aes(label = current_rownames, colour = Treatment),
 data = data.frame(
  current_rownames = current_rownames,
  Treatment = wine.data.filt$Treatment
 ),
 # more arguments here
)

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there some way to customize colours for the View output?

2024-05-07 Thread Ivan Krylov via R-help
В Tue, 7 May 2024 09:51:55 +
Iago Giné Vázquez  пишет:

> In the View help, it is told that:
> 
> On Windows, the initial size of the data viewer window is taken
> from the default dimensions of a pager (see Rconsole), but adjusted
> downwards to show a whole number of rows and columns.

The Windows data editor lives in
src/library/utils/src/windows/dataentry.c [1]. There are references to
the array guiColors and indices dataeditbg, dataedituser, dataeditbg,
dataeditfg. I was able to find the colours with these names in the GUI
preferences, edit them and see an effect on the edit() window.

-- 
Best regards,
Ivan

[1]
https://svn.r-project.org/R/trunk/src/library/utils/src/windows/dataentry.c

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using intervals() function for nlme model - Statistics Lab ETHZ

2024-05-06 Thread Ivan Krylov via R-help
Dear Tatiana, Marvin & Paul,

If you don't get a better answer here, try
r-sig-mixed-mod...@r-project.org.

On Fri, 3 May 2024 11:29:19 +
"Bielakova  Tatiana"  wrote:

> Based on the documentation of nlme package, the function interval is
> supported for gls, lme, and lmList classes. Although nlme is not
> mentioned, we still receive intervals without any errors or warnings.

You're right to question this. Programming-language-level inheritance
ends up being backwards for statistical methods:
.
Linear mixed-effect models are a subset of the more general mixed-effect
models, but in R, "nlme" objects inherit from "lme", not the other way
around.

>   *   Do you have any other recommendations/ ideas on how should we
> proceed to calculate intervals in R (e.g. more suitable packages)?

Here's a vignette from the nlraa package where bootstrap is used to get
a confidence interval for an implicit parameter:
https://cran.r-project.org/package=nlraa/vignettes/Bootstrapping.html

The author seems to be using intervals() on an nlme model without any
problems. It may help to see if the intervals() output agrees with the
bootstrap results from nlraa::boot_nlme().

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R CMD check vs RStudio check

2024-05-03 Thread Ivan Krylov via R-help
В Fri, 3 May 2024 19:45:08 +
"Boylan, Ross via R-help"  пишет:

> & $R CMD check .

> * checking for file './DESCRIPTION' ... ERROR
> Required fields missing or empty:
>   'Author' 'Maintainer'

You're checking a source package directory. This could work, but it's
much easier and more reliable to (1) build a source tarball using R CMD
build and (2) check the tarball. This is probably part of what
devtools::check() does. (It can also do a lot of other things pre-R CMD
build.)

The reason checking the source directory is failing is because it's R
CMD build that creates the necessary 'Author' and 'Maintainer' fields
from Authors@R in your DESCRIPTION.

> P.S. What's with the "..Rcheck" log directory, which appears
> literally with the 2 dots?  Is this just MS-Windows getting confused
> and not interpreting .. as the parent directory?

"..Rcheck" is built from the argument of R CMD check . followed by
".Rcheck".

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] grDevices segfault when building R4.4.0 on RHEL 9.1.

2024-05-03 Thread Ivan Krylov via R-help
Dear Miguel Esteva,

I couldn't get a Red Hat "ubi9" container to install enough
dependencies to build R. Is there a way to reproduce your setup on a
virtual machine somewhere?

On Fri, 3 May 2024 00:42:43 +
Miguel Esteva via R-help  wrote:

>  *** caught segfault ***
> 
> address 0x1801fa8f70, cause 'memory not mapped'
> 
> 
> Traceback:
> 
>  1: solve.default(rgb)

This seems to crash inside the BLAS. Which BLAS are you using? Any
custom ./configure arguments? Which compilers are you running?

To find out more information about the crash, try to follow it with a
debugger. Change directory to src/library/grDevices and run:

_R_COMPILE_PKGS_=1 R_COMPILER_SUPPRESS_ALL=1 \
 R_DEFAULT_PACKAGES=NULL LC_ALL=C \
../../../bin/R -d gdb --vanilla --no-echo -e \
 'tools:::makeLazyLoading("grDevices")'

(This assumes building straight from the source directory. Adjust the
paths if you're using a separate build directory.)

Use the "run" command to start the process. One you see a crash, use
"backtrace" to see the state of the call stack at the place of the
crash, or "backtrace full" to include the contents of local variables.
The first few entries are probably the most important ones.

Not sure what to do with this information yet, but it might provide
more clues.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strange behavior in base::as.double

2024-05-01 Thread Ivan Krylov via R-help
В Wed, 1 May 2024 11:32:32 -0400
Carl Witthoft  пишет:

> but as.double('123e') returns 123 -- or whatever the first digit is.

Nicely spotted problem!

Prof. Brian D. Ripley has fixed it in R-devel revision 86436 [*]. Now
as.double('123e') will also return NA. I think that the fix will become
part of R-4.4.1 when it's released.

-- 
Best regards,
Ivan

[*]
https://github.com/r-devel/r-svn/commit/9069a729f5bf69de8250a4c91dd482fcf64e1154

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] De-serialization vulnerability?

2024-05-01 Thread Ivan Krylov via R-help
В Wed, 1 May 2024 16:57:18 +
"Howard, Tim G \(DEC\) via R-help"  пишет:

> Is this real?

Yes, but with a giant elephant in the room that many are overlooking.
It has actually always been much worse.

Until R-4.4.0, there used to be a way for readRDS() to return an
unevaluated "promise object". When you access the returned value, the
code attached to the promise object is evaluated. Starting with
R-4.4.0, this particular ability is now forbidden. One particular
attack is now prevented, but the whole class of attacks is still
fundamentally impossible to avoid. The resulting increase in safety is
very small.

The R data files, both those produced by save() and opened by load(),
and those produced by saveRDS() and readRDS(), contain _internal_
object state. The code processing those objects trusts the internal
object state, because it has no other alternative, no other source of
state. This is true of all of base R, CRAN and BioConductor.

Many R objects contain executable code. For example, many saved models
contain -- as part of this internal state that gets stored inside *.rds
and *.RData files -- executable expressions that produce model matrices
from data frames. It is trivial for any aspiring attacker to take such
an object and replace the model expression with one that would take over
your system. When you perform ordinary R operations on the doctored
object, the attacker-provided "model expression" instead does whatever
the attacker wants.

The above was just one example of "trusting the internal state". An
attacker can come up with similar attacks for ALTREP objects, 'glue'
strings and a lot of other features of R, without ever touching
promises (the topic of CVE-2024-27322) or exploiting parser
vulnerabilities.

One safe way to move forward is to set aside a strict subset of R Data
Serialization format that cannot be used to create any executable code
or touch potentially vulnerable state (such as ALTREP, I think) and
reject all other features of RDS. Yes, this abandons the ability to
save model objects and many other great features of R serialization,
including those that make 'parallel' clusters possible. (But we trust
our clusters and should use regular serialize() with them.) I've been
working on this today; it's very raw, not even a package yet, and it
doesn't even read some of my data correctly, but I believe it's a
secure way forward: https://codeberg.org/aitap/unserializeData

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] function import file csv Openair

2024-04-30 Thread Ivan Krylov via R-help
Dear Evelina Ballato,

В Tue, 30 Apr 2024 10:36:32 +
Evelina Ballato  пишет:

> In the Openair package it is possible to restore the import csv file
> function?

This question is best addressed to the maintainer of the package (see
the output of maintainer("openair")) if not to their GitHub issues at
.

Searching the manual of the 'openair' package for "CSV" gives a few
results, so it might be possible that the functionality is still there,
just under a different name. The manual also says that the package uses
utils::read.csv to import the CSV files.

Which particular functionality you are currently missing from the
openair package?

If all else fails, you can go to
https://cran.r-project.org/src/contrib/Archive/openair/ and try to
install an older version of the package (2.11?) from there.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Tidyverse/dplyr solution for filling values of a tibble/dataframe from a column with a nested list.

2024-04-19 Thread Ivan Krylov via R-help
В Thu, 18 Apr 2024 16:31:46 +
"Deramus, Thomas Patrick"  пишет:

> Basically, each list contains a set of doubles, with the first
> indicating a specific index (based on the 0 beginning python​ index),
> and a certain value (e.g. 0.5).
> 
> What I would like to do is generate set of columns based on the rang
> of unique indexes of each nested list. e.g.: col_1, col_2, col_3,
> col_4, col_5​

It's possible to golf it down to something like the following:

newcol <- t(sapply(tibble$nestedvals, \(x) {
 x <- simplify2array(x)
 ret <- numeric(5)
 ret[x[1,]] <- x[2,]
 ret
}))

...which you can then rename and cbind() to your tibble.

But the problem remains that the desired data structure has to be
generated row by row and then transformed back into a column-oriented
data structure. Do you need a sparse matrix?

spec <- do.call(cbind, Map(
 \(row, cols) rbind(row, simplify2array(cols)),
 seq_along(tibble$nestedvals), tibble$nestedvals
))
sparse <- Matrix::sparseMatrix(spec[1,], spec[2,], x = spec[3,])

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Import multiple tif raster

2024-04-18 Thread Ivan Krylov via R-help
В Thu, 18 Apr 2024 19:04:04 +0200
 пишет:

> Solution: direct and full path to the .tif files.
> I confused back and forward slash

Congratulations on solving the problem yourself!

Here's a few more options that could be useful in the future:

1. Double the backslashes. Between single quotes ('...') and double
quotes ("..."), backslashes have a special meaning. This makes it
possible to enter characters without typing them directly (e.g. '\uf6'
results in "ö") or put quotes inside quoted strings (e.g. message('\'')
prints a single quote), but in order to mean \, you have to type \\:

path = "C:\\Users\\Sibylle 
Stöckli\\Desktop\\NCCS_Impacts_Lot2_2022\\InVEST\\Species_Input\\valpar_bee_presence"

2. Use the special "raw character constant" syntax where backslashes
don't have a special meaning:

path = r"{C:\Users\Sibylle 
Stöckli\Desktop\NCCS_Impacts_Lot2_2022\InVEST\Species_Input\valpar_bee_presence}"

These two options are explained in help(Quotes).

3. Instead of typing the path, use choose.dir() (Windows only, I think)
and select it interactively. You can print() the return value and copy
and paste it into the script later.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Import multiple tif raster

2024-04-18 Thread Ivan Krylov via R-help
В Thu, 18 Apr 2024 11:08:33 +0200
SIBYLLE STÖCKLI via R-help  пишет:

> > #to check the index numbers of all imported raster list elements
> > allrasters  
> list()
> > 
> > #call single raster element
> > allrasters[[1]]  
> Error in allrasters[[1]] : subscript out of bounds

`allrasters` is an empty list, so it doesn't have a first item.
Therefore, allrasters[[1]] is an error. Why is this so? Probably
because list.files(...) above returned an empty vector.

Check rastlist and/or length(rastlist). Make sure that the path you're
giving to list.files (the one starting with
/NCCS_Impacts_Lot2_2022/InVEST/...) exists on your computer. Did you
mean to start it with a slash, making it an absolute path starting from
the root of the filesystem?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Debugging functions defined (locally) inside another functions

2024-04-12 Thread Ivan Krylov via R-help
В Fri, 12 Apr 2024 12:53:02 +
Iago Giné Vázquez  пишет:

> How should I call trace() if f was a function?

Let the tracer be quote(debug(g)) and use as.list(body(f)) to determine
where it should be injected:

f <- function() {
 message('exists("g") so far is ', exists('g'))
 g <- function() {
  flag <- TRUE
  if (flag) stop('an error')
 }
 message('about to run g()')
 g()
}

In this example, step number 4 is message("about to run g()"), so
injecting a call to debug() before it should work:

trace(f, quote(debug(g)), at = 4)
f()
# exists("g") so far is FALSE
# Tracing f() step 4 # <-- at this point debug(g) is run
# about to run g()
# debugging in: g()
# debug at #3: {
#flag <- TRUE
# if (flag)
# stop("an error")
# }

help(trace) has an extensive example showing how to use it for many
similar purposes.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Debugging functions defined (locally) inside another functions

2024-04-12 Thread Ivan Krylov via R-help
В Fri, 12 Apr 2024 12:15:07 +
Iago Giné Vázquez  пишет:

> f <- function(whatever){
>...
>g <- function(whatever2){
>  ...
>}
>...
> }
> 
> If I wanted to debug some thing directly inside f I would do
> debug(f). But this does not go inside g code. On the other hand,
> debug(g) does not work as g is not a defined function in the
> namespace of the package.

Moreover, `g` doesn't exist at all until f() is evaluated and reaches
this point. If `f` was a function, it would be possible to trace() it,
inserting a call to debug(g) after it's created.

> f <- ggplot2::ggproto(...)
> 
> So debug(f) produces
> Error in debug(f) : argument must be a function

Can you show more information about the call that produces `f`? Where
does `g` come into play? Following ?ggplot2::ggproto, I can trigger the
browser if I reach into the environment of the publicly available
method:

Adder <- ggproto(...) # from the example
debug(environment(Adder$add)$add)
Adder$add(1234)
# debugging in: add(..., self = self)
# debug на #3: {
# self$x <- self$x + n
# self$x
# }

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with base::order

2024-04-10 Thread Ivan Krylov via R-help
В Wed, 10 Apr 2024 09:33:19 +0200
Sigbert Klinke  пишет:

> decreasing=c(F,F,F)

This is only documented to work with method = 'radix':

>> For the ‘"radix"’ method, this can be a vector of length equal to
>> the number of arguments in ‘...’ and the elements are recycled as
>> necessary.  For the other methods, it must be length one.

> na.last=c(T,T,T), 

I think this is supposed to be a scalar, no matter the sort method. At
the very least, I don't see it documented to accept a logical vector,
and the C code in both src/main/sort.c and src/main/radixsort.c treats
the argument as a scalar (using asLogical(...), not LOGICAL(...) on the
R value).

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to set the correct libomp for R

2024-04-09 Thread Ivan Krylov via R-help
В Tue, 9 Apr 2024 09:55:06 +0200
gernop...@gmx.net пишет:

> If I only move away /usr/local/lib/libomp.dylib, I can still install
> it. So it seems that also here the internal libomp.dylib from R is
> used. Just the bundled omp files at /usr/local/include (omp-tools.h,
> omp.h, ompt.h) seem to be used. So maybe this is caused by a mismatch
> of these file and the used libomp.dylib?

This is valuable information, thank you. This is evidence in favour of
libomp.dylib mismatch causing the problem. I hope that the backtrace
will help shine more light on the problem.

I'm out of ideas for now, but if I get any, I'll send another message.
If you don't get an answer here, try r-sig-...@r-project.org.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] CEoptim problems

2024-04-09 Thread Ivan Krylov via R-help
В Tue, 9 Apr 2024 12:04:26 +0200
Adelchi Azzalini  пишет:

> res <- CEoptim(sumsqrs, f.arg = list(xt), continuous = list(mean =
> c(0, 0, 0), sd = rep(1,3), conMat = A, conVec = b), discrete =
> list(categories = c(298L, 298L), smoothProb = 0.5),N = 1, rho
> = 0.001)
> 
> Error in is.null(A) || is.na(A) : 
>   'length = 18' in coercion to 'logical(1)'

There is a book titled "The R Inferno" with lots of debugging tips for
R: https://www.burns-stat.com/documents/books/the-r-inferno/

Start with a traceback(). Which function gave a matrix to the ||
operator (which accepts only logical scalars)?

If traceback is not enough, use options(error = recover). Once the
error happens, you will be able to inspect local variables inside any
of the active call frames, which may help understand where did A come
from and why it was given to the || operator.

Good luck!

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Exceptional slowness with read.csv

2024-04-08 Thread Ivan Krylov via R-help
В Sun, 7 Apr 2024 23:47:52 -0600
Dave Dixon  пишет:

>  > second_records <- read.csv(file_name, skip = 2459465, nrows = 5)

It may or may not be important that read.csv defaults to header =
TRUE. Having skipped 2459465 lines, it may attempt to parse the next
one as a header, so the second call read.csv() should probably include
header = FALSE.

Bert's advice to try scan() is on point, though. It's likely that the
default-enabled header is not the most serious problem here.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to set the correct libomp for R

2024-04-08 Thread Ivan Krylov via R-help
В Mon, 8 Apr 2024 10:29:53 +0200
gernophil--- via R-help  пишет:

> I have some weird issue with using multithreaded data.table in macOS
> and I am trying to figure out, if it’s connected to my libomp.dylib.
> I started using libomp as stated here:
> https://mac.r-project.org/openmp/

Does the behaviour change if you temporarily move away
/usr/local/lib/libomp.dylib? 

> P.S.: If you need some more details about the actual issue with
> data.table you can also check here
> (https://github.com/rstudio/rstudio/issues/14517) and here
> (https://github.com/Rdatatable/data.table/issues/5957)

The debugger may be able to shed more light on the problem than just
"yes, this is due to OpenMP":
https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196

When you reproduce the crash, what does the backtrace say?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] duplicated() on zero-column data frames returns empty

2024-04-07 Thread Ivan Krylov via R-help
В Fri, 5 Apr 2024 16:08:13 +
Jorgen Harmse  пишет:

> if duplicated really treated a row name as part of the row then
> any(duplicated(data.frame(…))) would always be FALSE. My expectation
> is that if key1 is a subset of key2 then all(duplicated(df[key1]) >=
> duplicated(df[key2])) should always be TRUE.

That's a good argument, thank you!

Would you suggest similar changes to duplicated.matrix too? Currently
it too returns 0-length output for 0-column inputs:

# 0-column matrix for 0-column input
str(duplicated(matrix(0, 5, 0)))
# logi[1:5, 0 ] 

# 1-column matrix for 1-column input
str(duplicated(matrix(0, 5, 1)))
# logi [1:5, 1] FALSE TRUE TRUE TRUE TRUE

# a dim-1 array for >1-column input
str(duplicated(matrix(0, 5, 10)))
# logi [1:5(1d)] FALSE TRUE TRUE TRUE TRUE

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] duplicated() on zero-column data frames returns empty vector

2024-04-05 Thread Ivan Krylov via R-help
Hello Mark,

В Fri, 5 Apr 2024 03:58:36 + (UTC)
Mark Webster via R-help  пишет:

> I found what looks to me like an odd edge case for duplicated(),
> unique() etc. on data frames with zero columns, due to duplicated()
> returning a zero-length vector for them, regardless of the number of
> rows:

> df <- data.frame(a = 1:5)
> df$a <- NULLnrow(df)
> # 5 (row count preserved by row.names)
> duplicated(df)
> # logical(0), should be c(FALSE, TRUE, TRUE, TRUE, TRUE)
> anyDuplicated(df)
> # 0, should be 2

> This behaviour isn't mentioned in the documentation; is there a
> reason for it to work like this?

<...>

> I admit this is a case we rarely care about.However, for an example
> of this being an issue, I've been running into it when treating data
> frames as database relations, where they have one or more candidate
> keys (irreducible subsets of the columns for which every row must
> have a unique value set).

Part of the problem is that it's not obvious what should be a
zero-column but non-zero-row data.frame mean.

On the one hand, your database relation use case is entirely valid. On
the other hand, if data.frames are considered to be tables of data with
row.names as their identifiers, then duplicated(d) should be returning
logical(nrow(d)) for zero-column data.frames, since row.names are
required to be unique. I'm sure that more interpretations can be
devised, requiring some other behaviour for duplicated() and friends.

Thankfully, duplicated() and anyDuplicated() are generic functions, and
you can subclass your data frames to change their behaviour:

duplicated.database_relation <- function(x, incomparables = FALSE, ...)
 if (length(x)) return(NextMethod()) else c(
  FALSE, rep(TRUE, nrow(x) - 1)
 )
.S3method('duplicated', 'database_relation')

anyDuplicated.database_relation <- function(
 x, incomparables = FALSE, ...
) if (nrow(x) > 1) 2 else 0
.S3method('anyDuplicated', 'database_relation')

x <- data.frame(row.names = 1:5)
class(x) <- c('database_relation', class(x))

duplicated(x)
# [1] FALSE  TRUE  TRUE  TRUE  TRUE
anyDuplicated(x)
# [1] 2
unique(x)
# data frame with 0 columns and 1 row

> [[alternative HTML version deleted]]

Since this mailing list eats the HTML parts of the e-mails, we only get
the plain text version automatically prepared by your mailer. This one
didn't look so good:
https://stat.ethz.ch/pipermail/r-help/2024-April/479143.html

Composing your messages to the list in plain text will help avoid the
problem.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with new version of R: Mutated vocals

2024-03-22 Thread Ivan Krylov via R-help
В Fri, 22 Mar 2024 16:11:14 +
MACHO Siegfried via R-help  пишет:

> If I type the command:
> Dir <- "C/Users/macho/Documents/_LVn/Experimentelle _bungen"
> in the R console there is no problem. However, if I put the same
> command into a source file (e.g. Test.r) and call this file from R
> (via the source command), I get the following error message:
> 
> > source("C:\\Users\\macho\\Documents\\_LVn\\Experimentelle
> > _bungen\\R-Scripts\\R-Dokumentation\\R_scripts zur
> > R_Dokumentation\\Kapitel 4 Erstellen eines
> > Balkendiagramms\\Test.R")  
> Fehler: invalid multibyte character in parser
> (C:\Users\macho\Documents\_LVn\Experimentelle
> _bungen\R-Scripts\R-Dokumentation\R_scripts zur
> R_Dokumentation\Kapitel 4 Erstellen eines Balkendiagramms\Test.R:1:54

A few versions ago, the R developers made the change of the encoding
used by R on Windows. Instead of the ANSI encoding, R now uses UTF-8:
https://blog.r-project.org/2020/05/02/utf-8-support-on-windows/index.html

This makes it possible to represent many more characters than the
256-byte range covered by CP1252, but the byte sequences are now
different. Also, non-ASCII characters will take more than one byte to
store.

Can you save the script using the UTF-8 encoding instead of CP1252?
Alternatively, try source(..., encoding = 'CP1252').

> In addition, text files saved with an older version of R (using the
> function write.table) containing mutated vowels are not read-in
> correctly by the function read.table.

In a similar manner, try read.table(..., fileEncoding = 'CP1252').
Setting encoding = 'latin1' may also work, even if it's technically a
different encoding.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error message

2024-03-22 Thread Ivan Krylov via R-help
В Fri, 22 Mar 2024 14:52:05 -0500
Val  пишет:

> : 8d5a 35f8 1ac5 cc14 a04e be5c 572f a3ad  .Z5..N.\W/..
> 0010: 6210 7024 9b58 93c7 34d0 acb7 7a82 3f99  b.p$.X..4...z.?.

Thank you!

This doesn't look like any structured data to me. In particular, it
doesn't look like something written by R: those created by modern
versions of R with default settings typically start with an "RDX2\n"
(52 44 58 32 0a) or at least "X\n" (58 0a). Could be a middle of
compressed stream, as if the file was truncated while it was being
written.

Do you get similar results with saveRDS(datafilename, 'X1.rds') and
data2 <- readRDS('X1.rds')? Does this happen with other R objects that
you try to save or in your other scripts?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error message

2024-03-22 Thread Ivan Krylov via R-help
В Fri, 22 Mar 2024 14:31:17 -0500
Val  пишет:

> How do I get the first   few bytes?

What does file.info('X1.RData') say?

Do you get any output if you run print(readBin('X1.RData', raw(), 128))?

If this is happening on a Linux or macOS machine, the operating system
command xxd -l 128 X1.RData will give the same output in a more
readable manner, but the readBin(...) output from R should be fine too.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error message

2024-03-22 Thread Ivan Krylov via R-help
В Fri, 22 Mar 2024 14:02:09 -0500
Val  пишет:

> X2.R
> load("X1.RData")
> 
> I am getting this error message:
>  Error in load("X1.RData", :
>  bad restore file magic number (file may be corrupted)  .. no data
> loaded.

This error happens very early when R tries to load the file, right
at the first few bytes. Is "X1.RData" large? Can you share it, or at
least a hexadecimal dump of the first few hundred bytes?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building Packages.

2024-03-21 Thread Ivan Krylov via R-help
В Thu, 21 Mar 2024 18:45:35 +
Jorgen Harmse via R-help  пишет:

> The problem may have been that this package is so important to me
> that I put it in .Rprofile. The package was not installed for the new
> version of R, so every R session started with an annoying error
> message. Presumably a separate session started with R CMD would just
> fail without installing the package.

This must be the solution to the mystery. I have recently added some
code that raised an error (lattice::standard.theme(...), but without a
new enough 'lattice' to understand the arguments) to my .Rprofile, and
it broke quite a few things related to package development until I fixed
my .Rprofile.

Congratulations on solving the problem!

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building Packages.

2024-03-20 Thread Ivan Krylov via R-help
В Wed, 20 Mar 2024 19:26:53 +
Jorgen Harmse  пишет:

> Thank you. tools:::.install_packages works.

I'm glad it works, but it shouldn't be necessary to use (and is not
part of the API: not documented to keep working this way).

Since you're already using devtools, perhaps devtools::install will
succeed. But it's not obvious why utils::install.packages() is failing,
and it should still be called by devtools::install().

> It happens that one of the functions in my package is a utility to
> build packages. I guess I should change the install step.

Try setting a breakpoint in system2 before launching your function:

debugonce(system2)
build.package('/path/to/the/source/tree')

This should land you in R's "browser" (see help(browser) for how to use
it). At this point, what is `command` and what are the `args`? If you
remove c("CMD", "INSTALL") from the `args` vector and give the rest as
the argument to .install_packages() in a fresh process, will it break
in a similar manner?

Browse[2]> command
[1] "/usr/lib/R/bin/R"
Browse[2]> args
[1] "CMD" "INSTALL" "-l"
"'/home/ivan/R/x86_64-pc-linux-gnu-library/4.2'"
"'/home/ivan/path/to/package_1.0.tar.gz'"

# (start a new process)

tools:::.install_packages(c(
 '-l',
 # you'll have to manually unquote the file paths:
 # the strings above are for both R and the command line shell
 # to interpret, but here we're only giving them to R, not the shell
 "/home/ivan/R/x86_64-pc-linux-gnu-library/4.2",
 "/home/ivan/path/to/package_1.0.tar.gz"
))

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building Packages.

2024-03-20 Thread Ivan Krylov via R-help
В Wed, 20 Mar 2024 17:00:34 +
Jorgen Harmse  пишет:

> Thank you, but I think I was already using utils.
> 
> Regards,
> Jorgen.
> 
> 
> > environment(install.packages)  
> 
> 
> 
> > utils::install.packages('/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz',type='source',repos=NULL)
> >  
> 
> Error in library(jhBase) : there is no package called ‘jhBase’

Sorry, then it has been my mistake to blame RStudio for this.

We can try debugging this. If you start a fresh R process and run
tools:::.install_packages(path_to_tarball), the installation will (try
to) proceed in the current process instead of a child process. Once it
fails, traceback() will be available to show you where the error
condition has been raised. What does it say?

Alternatively,

1. Check the package R files for stray library() calls. Generally,
packages should not be calling library().

2. Try a "binary search" approach. Make a copy of your package code but
remove half of the files (or half of the functions if they live in a
single file). Keep removing a half (or go to the other half) depending
on whether the same error keeps happening.

Good luck!

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building Packages.

2024-03-20 Thread Ivan Krylov via R-help
В Wed, 20 Mar 2024 12:37:39 -0400
Ben Bolker  пишет:

> Ivan, can you give more detail on this? I've heard this issue 
> mentioned, but when I open RStudio and run find("install.packages")
> it returns "utils::install.packages", and running dump() from within 
> RStudio console and from an external "R --vanilla" gives identical
> results.

Has this been fixed in a recent RStudio version? This is what I get on
a Windows virtual machine:

> install.packages
function (...) 
.rs.callAs(name, hook, original, ...)

> install.packages(file.choose())
Installing package into ‘C:/Users/User/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘C:\path\to\mypackage_1.0.tar.gz’ is not available
for this version of R

A version of this package for your version of R might be available
elsewhere, see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
> utils::install.packages(file.choose())
Installing package into ‘C:/Users/User/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
inferring 'repos = NULL' from 'pkgs'
* installing *source* package 'mypackage' ...
** using staged installation
** libs

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building Packages.

2024-03-20 Thread Ivan Krylov via R-help
В Wed, 20 Mar 2024 16:02:27 +
Jorgen Harmse via R-help  пишет:

> > install.packages(tar,type='source',repos=NULL)  
> 
> Error in library(jhBase) : there is no package called ‘jhBase’
> 
> Execution halted
> 
> Warning in install.packages(tar, type = "source", repos = NULL) :
> 
>   installation of package
> ‘/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz’
> had non-zero exit status

Using RStudio? It happens to override install.packages with a function
that doesn't quite handle file paths. Try utils::install.packages(tar,
type = "source", repos = NULL).

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.xlsx error message

2024-03-15 Thread Ivan Krylov via R-help
В Thu, 14 Mar 2024 14:12:12 +
Subia Thomas OI-US-LIV5  пишет:

> Using write.xlsx to extract data from an Excel file, I get this error
> message.
> 
> 
> Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod",
> cl,  : java.lang.OutOfMemoryError: GC overhead limit exceeded

There seems to be a default limit of 512 megabytes for the Java heap
size:

library(rJava)
getOption('java.parameters')
# [1] "-Xmx512m"

Does if help if you set options(java.parameters = '-Xmx2048m') (or
as much as you feel comfortable with) before loading XLConnect?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Generating mouse click and hold using R

2024-03-13 Thread Ivan Krylov via R-help
В Wed, 13 Mar 2024 19:01:59 +0530
Christofer Bogaso  пишет:

> I need simulate mouse click in windows machine at certain coordinate
> on screen and hold the click for certain seconds e.g. for 5 seconds

There's no interface for this in base R. It's always possible to write
some Windows API code to do that and call it from R using .Call()
(SendInput() is relatively easy to use [*]), but that takes effort and
knowledge of C.

What I suggest to do instead is to write an AutoHotKey script, making
use of the Click function [**] and taking arguments from the command
line [***], and then launch that script using system2(). AutoHotKey is
free software (GPLv2), designed specifically to automate other programs
and should be much easier to use correctly than C.

-- 
Best regards,
Ivan

[*]
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput

[**]
https://www.autohotkey.com/docs/v2/lib/Click.htm

[***]
https://www.autohotkey.com/docs/v2/Scripts.htm#cmd

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with R coding

2024-03-12 Thread Ivan Krylov via R-help
В Tue, 12 Mar 2024 14:57:28 +
CALUM POLWART  пишет:

> That's almost certainly going to be either the utf-8 character in the
> path

The problem, as diagnosed by Maria in the first post of the thread, is
that the user home directory as known to R is stored in the ANSI
encoding instead of UTF-8, despite the session charset should be UTF-8
as Maria's Windows is sufficiently new [*]. As soon as any bit of R
tries to perform an encoding conversion using this path (for example,
file.exists() converting it from UTF-8 to UCS-2 in order to interact
with Windows filesystem APIs), the conversion fails. Since tcltk2 uses
file.exists('~/...') in its .onLoad, the package and any of its hard
dependencies are now broken.

Normally, this path is determined automatically to be something like
C:\Users\username\Documents. With OneDrive taking over, it turns out to
be something else and for some reason in the wrong encoding (ANSI but
marked as native == UTF-8).

The function that determines this path lives in src/gnuwin32/shext.c
(char *getRUser(void)). It starts by looking at the environment
variable R_USER, which is why in order to override OneDrive, the user
has to set it first (in the command line or system settings). If that
fails, R tries the environment variable HOME (which is usually set on
Windows, isn't it?), consults SHGetKnownFolderPath(FOLDERID_Documents)
(which returns the result as a wchar_t[] to be manually converted to
UTF-8 by R), consults a few more environment variables, and finally
tries to use the current directory. There is likely no easy way to use
`subst` to give a different home drive to R.

If I set %HOME% or even %R_USER% to a non-ASCII path without setting up
OneDrive, R works normally, so getenv() must be able to return
UTF-8-encoded variables. I don't see how ShellGetPersonalDirectory()
could fail in this manner. My remaining hypothesis is that OneDrive
somehow causes getenv("HOME") to return "C:\\Users\\marga\\OneDrive
- Fundación Universitaria San Pablo CEU\\Documentos" in ANSI instead of
UTF-8.

If anyone here has OneDrive set up in this manner and can debug R,
a trace of what getRUser() actually does would be very useful.

-- 
Best regards,
Ivan

[*]
https://blog.r-project.org/2020/05/02/utf-8-support-on-windows/index.html
https://blog.r-project.org/2022/11/07/issues-while-switching-r-to-utf-8-and-ucrt-on-windows/index.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with R coding

2024-03-12 Thread Ivan Krylov via R-help
Dear Maria,

I'm sorry for somehow completely missing the second half of your
message where you say that you've already tried the workaround.

В Tue, 12 Mar 2024 07:43:08 +
Maria Del Mar García Zamora  пишет:

> I have tried to start R from CDM using: C:\Users\marga>set
> R_USER=C:\Users\marga\R_USER
> 
> C:\Users\marga>"C:\Users\marga\Desktop\R-4.3.3\bin\R.exe" CMD Rgui  
> 
> At the beginning this worked but right now a message saying that this
> app cannot be used and that I have to ask the software company (photo
> attached)

Glad to know the workaround helped. It sounds like your Windows
10 is set up in a user-hostile way.

It may help to visit the Windows Security settings and make an
exception for C:\Users\marga\Desktop\R-4.3.3\bin\R.exe. An approximate
instruction can be found at
, but it
might be the case that your university IT must take a look at it before
allowing you to run R on your computer.

Feel free to disregard this advice if someone with more Windows
experience shows up.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with R coding

2024-03-12 Thread Ivan Krylov via R-help
В Tue, 12 Mar 2024 07:43:08 +
Maria Del Mar García Zamora  пишет:

> Error: package or namespace load failed for ‘Rcmdr’:
>  .onLoad failed in loadNamespace() for 'tcltk2', details:
>   call: file.exists("~/.Rtk2theme")
>   error: file name conversion problem -- name too long?
> 
> Once this appears I use path.expand('~') and this is R's answer:
> [1] "C:\\Users\\marga\\OneDrive - Fundaci\xf3n Universitaria San
> Pablo CEU\\Documentos"

We've seen this problem before:
https://stat.ethz.ch/pipermail/r-help/2023-December/478732.html

The workaround that should help is to set the R_USER environment
variable to C:\Users\marga before launching R.

Please let me know if you're willing to debug R. (This will likely
involve compiling R from source with debugging symbols enabled and
stepping through the code.) There are no places in the Windows code
where R gets the conversion obviously wrong. I don't have OneDrive and I
wasn't able to convince R to return an invalid R_USER path without it.
I'm halfway convinced this is due to a bug in OneDrive itself.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [External] Function environments serialize to a lot of data until they don't

2024-03-11 Thread Ivan Krylov via R-help
Dear Luke,

Thank you for the detailed explanation of the power of force()! It does
solve my problem in a much more reliable manner than setting function
environments manually.

On Fri, 8 Mar 2024 15:46:52 -0600 (CST)
luke-tier...@uiowa.edu wrote:

> Having a reference to a large environment is not much of an issue
> within a single process, but can be in a distributed memory parallel
> computing context.  To avoid this you can force evaluation of the
> promises:
> 
>  mkLL1 <- function(m, s) {
>   force(m)
>   force(s)
>   function(x) sum(dnorm(x, m, s, log = TRUE))
>  }
>  ll <- f(1e7)
>  length(serialize(ll, NULL))
>  ## [1] 2146

I think this also illustrates the danger of letting side effects come
near function arguments. A promise to read a file could survive on a
cluster node and result in a lot of head-scratching. A promise to write
to the connection number N, which coincides with a connection open on
the cluster node, could even do some damage. This is definitely
something to remember when creating closures.

> A very simple tool available in the snow package for snow clusters is
> snow.time(), which can produce some summary times and a Gantt chart
> (patterned after ones produced by xpvm and xmpi).

I can see the snow.time() plot being useful. Thank you for letting me
know about it!

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Function environments serialize to a lot of data until they don't

2024-03-08 Thread Ivan Krylov via R-help
Hello R-help,

I've noticed that my 'parallel' jobs take too much memory to store and
transfer to the cluster workers. I've managed to trace it to the
following:

# `payload` is being written to the cluster worker.
# The function FUN had been created as a closure inside my package:
payload$data$args$FUN
# function (l, ...) 
# withCallingHandlers(fun(l$x, ...), error = .wraperr(l$name))
# 
# 

# The function seems to bring a lot of captured data with it.
e <- environment(payload$data$args$FUN)
length(serialize(e, NULL))
# [1] 738202878  
parent.env(e)
# 

# The parent environment has a name, so it all must be right here.
# What is it?

ls(e, all.names = TRUE)
# [1] "fun"
length(serialize(e$fun, NULL))
# [1] 317

# The only object in the environment is small!
# Where is the 700 megabytes of data?

length(serialize(e, NULL))
# [1] 536
length(serialize(payload$data$args$FUN, NULL))
# [1] 1722

And once I've observed `fun`, the environment becomes very small and
now can be serialized in a very compact manner.

I managed to work around it by forcing the promise and explicitly
putting `fun` in a small environment when constructing the closure:

.wrapfun <- function(fun) {
 e <- new.env(parent = loadNamespace('mypackage'))
 e$fun <- fun
 # NOTE: a naive return(function(...)) could serialize to 700
 # megabytes due to `fun` seemingly being a promise (?). Once the
 # promise is resolved, suddenly `fun` is much more compact.
 ret <- function(l, ...) withCallingHandlers(
  fun(l$x, ...),
  error = .wraperr(l$name)
 )
 environment(ret) <- e
 ret
}

Is this analysis correct? Could a simple f <- force(fun) have sufficed?
Where can I read more about this type of problems?

If this really is due to promises, what would be the downsides of
forcing them during serialization?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] installation: while running make, unable to run pdflatex on 'NEWS.tex'

2024-03-01 Thread Ivan Krylov via R-help
В Fri, 1 Mar 2024 10:46:53 -0500
Benjamin Tyner  пишет:

> my platform info:
> 
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 22.04.4 LTS

Quick things first: have you installed all the build-dependencies? apt
build-dep r-base (maybe with --install-suggests? haven't tried that in
a while) should do that. In particular, the build dependencies include
texlive-fonts-extra and texlive-latex-extra. That's a lot of packages,
but some of them are required to compile LaTeX documents produced by R.

> you should 'make docs' now ...
> make[1]: Entering directory '/home/btyner/R-4.3.3/doc'
> creating doc/NEWS
> creating doc/NEWS.pdf
> Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet =
> quiet, :
> unable to run pdflatex on 'NEWS.tex'
> LaTeX errors:
> ! LaTeX Error: File `pdftexcmds.sty' not found.

Can you compile a minimal LaTeX document? Something like:

\documentclass{article}
\begin{document}
\[ \mathbf{y} = \mathbf{X} \beta \]
\end{document}

Does tools::texi2pdf('THISFILE.tex') fail with a similar error message?

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dput(..., file = stderr())

2024-03-01 Thread Ivan Krylov via R-help
В Fri, 1 Mar 2024 10:54:08 -0500
Benjamin Tyner  пишет:

>  > dput(letters, file = stderr())  
> c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
> "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y",
> "z")
> Warning message:
> In dput(letters, file = stderr()) : wrote too few characters

Sounds like a bug.

This is where the warning is produced:

int res = Rconn_printf(con, "%s\n", CHAR(STRING_ELT(tval, i)));
if(!havewarned &&
   res < strlen(CHAR(STRING_ELT(tval, i))) + 1) {
warning(_("wrote too few characters"));
havewarned = TRUE;
}

At this point, `res` is 0, and CHAR(STRING_ELT(tval, i)) is what you'd
expect:

(gdb) x /s (void*)(STRING_ELT(tval, i))+48
0x561bf0a8: "c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\",
\"h\", \"i\", \"j\", \"k\", \"l\", "

`res` is 0 because that's what (con->vfprintf)(...) returns:

2813static int stderr_vfprintf(Rconnection con, const char *format, va_list 
ap)
2814{
2815REvprintf(format, ap);
2816return 0;
2817}

Why doesn't it warn for stdout()? Doesn't stdout_vfprintf(...) behave
the same? That's because stdout() (connection #1) is special for dput(),
and instead of going through the connection system, it goes straight for
Rprintf():

426 else { // ifile == 1 : "Stdout"
427 for (int i = 0; i < LENGTH(tval); i++)
428 Rprintf("%s\n", CHAR(STRING_ELT(tval, i)));
429 }

Not sure what the right fix is. There may be code depending on
(con->vfprintf)(...) returning 0.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Trouble reading a UTF-16LE file

2024-02-28 Thread Ivan Krylov via R-help
В Wed, 28 Feb 2024 13:44:49 +
"Ebert,Timothy Aaron"  пишет:

> readLines(file, encoding='utf-16LE')

There are two ways you could encounter an encoding in R.

First are encoding markers placed on every string object, which declare
the string to be encoded in UTF-8, Latin-1, the native locale encoding,
or ASCII or "bytes". No other encodings are supported. The "encoding"
argument of readLines() sets this marker.

In order to support other encodings, R is able to convert the text as
part of the input/output connections. help(readLines) points you
towards that: you need to set the UTF-16LE encoding on the connection
object.

con <- file(file, encoding = 'UTF16LE')
lines <- readLines(con)
close(con)

"UTF16LE" is not guaranteed to be supported, so see iconvlist() for the
encodings that should work with your build of R.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Clustering Functions used by Reverse-Dependencies

2024-02-28 Thread Ivan Krylov via R-help
В Sat, 24 Feb 2024 03:08:26 +
Leo Mada via R-help  пишет:

> Are there any tools to extract the function names called by
> reverse-dependencies?

For well-behaved packages that declare their dependencies correctly,
parsing the NAMESPACE for importFrom() and import() calls should give
you the explicit imports. (What if the package imports the whole
dependency? The safe assumption is that all functions are used, but it
comes with false positives. You could also walk the package code
looking for function names that may belong to the imported package, but
that may involve both false positives and false negatives.)

For the rest of the imports and uses of weak dependencies, you'll have
to walk the package code looking for the uses of the `::` operator. See
how R CMD check walks the package code in functions
tools:::.check_packages_used and codetools::checkUsage.

A less-well-behaved package can always load a namespace during runtime
and choose the functions to call depending on the phase of the moon or
weather on Jupiter. For these, like for the halting problem, there's no
general solution: the package could be written to say, "if Leonard's
function says I'm about to call foo::bar, I won't do it, otherwise I
will".

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] igraph_vertex

2024-02-26 Thread Ivan Krylov via R-help
В Mon, 26 Feb 2024 11:52:13 +0100
 пишет:

> TIFFOpen: figures/AES_network_bymembership.tiff: Cannot open.

> Warning message:
> In dev.off() :
>   unable to open TIFF file 'figures/AES_network_bymembership.tiff'

In the current directory (see getwd()), is there a subdirectory named
"figures"? Do you have write access to this subdirectory? Is there a
file named "AES_network_bymembership.tiff" in the subdirectory named
"figures"? Could it be open by a different program and therefore
locked?

Unfortunately, libtiff doesn't seem to provide any more information
regarding why it couldn't open the file at this point.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] igraph_vertex

2024-02-26 Thread Ivan Krylov via R-help
В Mon, 26 Feb 2024 09:02:56 +0100
SIBYLLE STÖCKLI via R-help  пишет:

> In the following code, which loads the tiff file, I get the following
> error

This warning is definitely worth investigating, but it shouldn't
interrupt your code. Does the figure come out wrong after you see this
warning?

> In doTryCatch(return(expr), name, parentenv, handler) : Character set
> family not found in the Windows character set database
> 
> --> I am unsure if mySQL is the right solution. I have no experience
> how to change mySQL. 

I see you've tried to do the right thing and searched for the warning
message. Unfortunately, the search engines are wrong; this doesn't seem
related to MySQL.

A similarly-worded warning message exists in the Windows-related font
functions inside R:

>> warning(_("font family not found in Windows font database"))

If running a sufficiently new version of R, try Sys.setLanguage('en')
before reproducing the problem and searching for the exact warning
message in double quotes. (Reset it back using
Sys.setLanguage(your_language_code) or restart R afterwards.)
Translated error and warning messages are good for understanding, but
they fragment the search engine results.

I see that a few messages back you set a font family:

>  vertex.label.family="Helvetica",

R probably doesn't know where to get it in order to render the plot as
TIFF. If you have a copy of Helvetica installed in your system, try
registering it using windowsFonts(Helvetica = windowsFont("how the
font is named in the system")). (See help(windowsFonts) for more
information.) Otherwise you may be limited to R's predefined font
families.

It's annoying that "Helvetica" exists for PDF plots and such seemingly
without a problem, but if you change the output format to TIFF, the set
of fonts available to you changes too. Unfortunately, there are
multiple different font rendering engines in play, and their predefined
lists of fonts also differ.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Network issue

2024-02-21 Thread Ivan Krylov via R-help
В Wed, 21 Feb 2024 06:09:51 +
James Powell  пишет:

> This was working fine until yesterday when I had error messages
> trying to install some packages. See enclosed “S2” for example. It
> looks like it is trying to download a file as part of the
> installation, but of course can’t. 

Since you're on Windows and running R-4.3, it should be easier to
download and install the binary package,
https://cran.r-project.org/bin/windows/contrib/4.3/s2_1.1.6.zip.

Installing this package from source involves downloading a few binaries
anyway. You could try unpacking the source package, downloading OpenSSL
1.1.1k binaries from https://github.com/rwinlib/openssl/tree/v1.1.1k
into a new subdirectory called windows/ in the package root, just like
the https://github.com/r-spatial/s2/blob/main/tools/winlibs.R script
tries to do during the installation, then installing the resulting
directory as if it was a source package.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Capturing Function Arguments

2024-02-18 Thread Ivan Krylov via R-help
В Sat, 17 Feb 2024 11:15:43 -0700
"Reed A. Cartwright"  пишет:

> I'm wrapping a function in R and I want to record all the arguments
> passed to it, including default values and missing values.

This is hard if not impossible to implement for the general case
because the default arguments are evaluated in the environment of the
function as it is running:

f0 <- function(arg = frobnicate()) {
 frobnicate <- switch(
  sample.int(3, 1),
  function() environment(),
  function(n=1) runif(n),
  function() alist(a=)$a
 )
 arg
}

(And some arguments aren't meant to be evaluated at all.)

Even starting with rlang::call_match(call = NULL, defaults = TRUE) is
doomed to a certain extent because it gives you f(x = a, a = NULL) for
both function(x, a = NULL), f(a) (where `a` passed as an argument `x`
and `a` should be taken from the parent frame) and function(x = a, a =
NULL), f() (in which case `x` defaults to `a`, which in turn defaults
to NULL).

I think the key here is evaluating the arguments first, then matching.
This makes a lot of assumptions about the function being inspected: no
NSE, no ellipsis, formals don't depend on the body, nothing weird about
the environment of the function...

f <- function(...) {
 .makemissing <- function() alist(a=)$a
 .ismissing <- function(x) identical(x, .makemissing())

 # prepare to evaluate formals
 params <- formals(f0)
 e <- new.env(parent = environment(f0))
 # assign non-missing formals
 for (n in names(params)) if (!.ismissing(params[[n]])) eval(
  # work around delayedAssign quoting its second argument
  call('delayedAssign', n, params[[n]], e, e)
 )

 # match the evaluated arguments against the names of the formals
 args <- as.list(match.call(f0, as.call(c('f0', list(...)[-1]
 for (n in names(args)) assign(n, args[[n]], envir = e)

 # evaluate everything, default argument or not
 mget(names(params), e, ifnotfound = list(.makemissing()))
}

f0 <- function(x, y = 2 * z, z, a = NULL, b) NULL
a <- 1
identical(
 f(a, z = 1 + 100),
 list(x = 1, y = 202, z = 101, a = NULL, b = rlang::missing_arg())
)
# [1] TRUE

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] print data.frame with a list column

2024-01-29 Thread Ivan Krylov via R-help
On Mon, 29 Jan 2024 14:19:21 +0200
Micha Silver  wrote:

> Is there some option to force printing the full list?

> df <- data.frame("name" = "A", "bands" = I(list(1:20)))

format.AsIs is responsible for printing columns produced using I(). It
accepts a "width" argument:

format(x, width = )
#   name bands
# 1A 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

It's more complicated with knitr::kable. Its format.args argument is
only used with numeric arguments, but you can pre-format the table with
knitr::kable(format(x, width = )).

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread Ivan Krylov via R-help
В Sat, 13 Jan 2024 20:33:47 + (UTC)
varin sacha via R-help  пишет:

> coef(lm(Score~ Time + factor(Country)),data=data[idx,])

Wrong place for the data=... argument. You meant to give it to lm(...),
but in the end it went to coef(...). Without the data=... argument, the
formula passed to lm() picks up the global variables inherited by the
func() closure.

Unfortunately, S3 methods really do have to ignore extra arguments they
don't understand if the class is to be extended, so coef.lm isn't
allowed to complain to you about it.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] arrow on contour line

2024-01-11 Thread Ivan Krylov via R-help
В Wed, 10 Jan 2024 19:13:19 -0500
Deepankar Basu  пишет:

> I am drawing contour lines for a function of 2 variables at one level
> of the value of the function and want to include a small arrow in any
> direction of increase of the function. Is there some way to do that?

Can you use the information about the function (i.e. the myg object),
or are you restricted to the d2 data.frame?

Both ggplot and the core graphics use the algorithm from the
contourLines() function in order to draw the contour lines. (Lattice
does the same, but ports the function from C to R.) This function
returns a list of levels combined with vectors of `x` and `y`
coordinates for drawing the contour.

If you can use the myg function, you can differentiate it numerically
or symbolically, process the contourLines() output, evaluate the
gradient at one point per contour and draw additional arrows there.

If you are limited to the tabulated function values from the d2
data.frame, you have a more complicated problem on your hands. You can
either locate grid points closest to the contour segments at both sides
of the segment, determine the direction of growth, and draw an arrow
perpendicular to the contour segment (not equal to the gradient), or
find a way to estimate the gradient at arbitrary points between the
grid (e.g. by using a Taylor series stencil) and then go to the
previous paragraph.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Truncated plots

2024-01-09 Thread Ivan Krylov via R-help
В Tue, 9 Jan 2024 16:42:32 +
Nick Wray  пишет:

> she has a problem with R studio on her laptop

Does the problem happen with plain R, without Rstudio?

What's the student's sessionInfo()?

> I have a screenshot which could email if anyone needs to see what it
> looks like.

I think that PNG screenshots are allowed on the mailing list, so it
could be very helpful if you attached an appropriately cropped
screenshot.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.