0

I’ve been having trouble loading a package onto CRAN. I am using R Studio to build my package and some lower-level C code for optimization. Within R Studio I'm able to load/build/check my package with no problems (I am using a Mac btw). However, when I build the package and submit it to CRAN, it's rejected with the following:

Flavor: r-devel-windows-ix86+x86_64
Check: running examples for arch 'x64', Result: ERROR

Upon looking at the log that is provided for me, the examples run perfectly fine for Debian and windows i386.

Does anyone have an idea as to why my examples fail for x64 but work fine on i386?

Below is the code in the 00check.log:

** running examples for arch 'i386' ... OK
** running examples for arch 'x64' ... ERROR
Running examples in 'fastcmprsk-Ex.R' failed
The error most likely occurred in:
.
.
.
> ### ** Examples
> 
> library(fastcmprsk)
> 
> set.seed(10)
> ftime <- rexp(200)
> fstatus <- sample(0:2, 200, replace = TRUE)
> cov <- matrix(runif(1000), nrow = 200)
> dimnames(cov)[[2]] <- c('x1','x2','x3','x4','x5')
> fit <- fastCrr(Crisk(ftime, fstatus) ~ cov, variance = FALSE)
* DONE
Status: 1 ERROR, 1 NOTE

I'm led to believe that the culprit is the fastCrr function. However, the example seems to have run fine for arch 'i386' (see above) and for Debian. I can't understand why it fails for x64, is there a hardware issue that I'm not aware of? The function I'm calling does call C for the optimization routine. Perhaps there's a leak somewhere but I double checked and made sure that I Free every Calloc variable. I'm not sure how else leaks can happen or why it'll only be specific to one system and not the other.

Hope this helps.

Thank you to all who've been viewing this and for your feedback.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • You can use `rhub::check_with_valgrind` to check for memory issues. – Ralf Stubner Aug 21 '19 at 07:49
  • x64 Windos is the "odd one out" when it comes to the size of `long`, c.f. https://stackoverflow.com/a/384672/8416610. Maybe if have some implicit assumptions? It is impossible to say more without seeing a [mre]. – Ralf Stubner Aug 21 '19 at 07:55
  • @RalfStubner what would be the best way to give a reproducible example? The R package is built as a .tar.gz but I doubt I can just upload it onto here. Any help would be appreciated. Also, check_with_valgrind showed no issues (examples ran fine) However when I do ```R CMD check --as-cran --use-valgrind ~/GitHub/fastcmprsk_1.0.3.tar.gz``` it fails on the example with the following error: ```valgrind: mmap-FIXED(0x7fff5f400000, 8388608) failed in UME (load_unixthread1) with error 22 (Invalid argument).``` – rivermouth91 Aug 21 '19 at 15:03
  • Is the error reproducible with (preferably) `rhub::check_on_windows` or `devtools::check_win_devel`? If it is reproducible, you can reduce the code as much as possible while still producing the error. In the end a short `.R` and a short `.c` fiel should be all that is needed to produce the error. Otherwise, you can upload your sources to code hosting platforms like GitHub or GitLab and post the link here. – Ralf Stubner Aug 21 '19 at 15:24
  • @RalfStubner the code itself is on GitHub: https://github.com/erickawaguchi/fastcmprsk (branch developer) – rivermouth91 Aug 21 '19 at 15:40

1 Answers1

1

Using the wch1/r-debug docker image I have run UBSAN tools on your code. The ones from gcc found something:

ralf@barra:~$ docker run --rm -it wch1/r-debug
root@9131acbabe1f:/# git clone https://github.com/erickawaguchi/fastcmprsk
root@9131acbabe1f:/# cd fastcmprsk/
root@9131acbabe1f:/fastcmprsk# git checkout developer
root@9131acbabe1f:/fastcmprsk# cd -
root@9131acbabe1f:/# RDsan -e "install.packages(c('doParallel', 'dynpred', 'codetools', 'survival'))"
root@9131acbabe1f:/# RDsan CMD build fastcmprsk
root@9131acbabe1f:/# RDsan CMD check fastcmprsk_1.0.3.tar.gz 
[...]
==5515==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6180002383d0 at pc 0x7ff3b5ad8d3f bp 0x7ffebeb2bb90 sp 0x7ffebeb2bb80  
READ of size 4 at 0x6180002383d0 thread T0
    #0 0x7ff3b5ad8d3e in ccd_dense /fastcmprsk.Rcheck/00_pkg_src/fastcmprsk/src/denseFit.c:148

Indeed, at https://github.com/erickawaguchi/fastcmprsk/blob/319138af6dfe5414608a89dbb168ea1e0ab1a797/src/denseFit.c#L148 you are reading from ici past the array boundary, since the test i == (n - 1) is evaluated after the test ici[i + 1] != 1. I would start there, even though I am not sure why this leads to a deterministic failure on x64 Windows.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • That seems to not be the issue. I'll double check. It does make sense that if statements run sequentially (I overlooked this). I was wondering how I would do this myself? How would I run ```wch1/r-debug``` and UBSAN on my code/package? I'm very new to debugging, especially when it comes to C coding and memory leaks etc. – rivermouth91 Aug 21 '19 at 21:22
  • @rivermouth91 See https://github.com/wch/r-debug/blob/master/debugging-r.md for a good overview on that docket image. – Ralf Stubner Aug 22 '19 at 04:59
  • Still have no luck. It still gets stuck at the same spot. I'm trying to understand how to use the docker image but it's a tad confusing. I downloaded everything but I don't know how to run UBSAN on my code/R package. I feel like I followed all the directions but when I try to run ```RDsan``` on my ```fastcmprsk_v1.0.3.tar.gz``` it says that it can't find the directory. I think it has something to do with the container but I'm not entirely sure. It'd be great to know what steps you took so I can have a better idea. Unless I'm misreading/misunderstanding the tutorial you sent me. – rivermouth91 Aug 23 '19 at 18:02
  • @rivermouth91 I have now included the full set of commands I have used. BTW, you should use `Imports` instead of `Depends` when referring to used packages. – Ralf Stubner Aug 26 '19 at 07:59