r - Unit testing with `testthat` on functions that write/read files, or a Fortran error -
what best way make unit testing testthat on functions read , write files?
apologies asking complicated question, not sure wrong here.
i have implemented number of functions in fortran, reads , writes files. compiled in r package cf. writing r extension manual. unit testing testthat generates random content written temporary files tempfile(). running r cmd check on r package works on local windows machine.
running r-devel fails because cannot detect rtools r-3.5.0 (devel). submitted win-builder.
http://win-builder.r-project.org/ fails following error:
@ line 9 of file auxil.f95 fortran runtime error: actual string length shorter declared 1 dummy argument 'fn' (96/255) with corresponding fortran source:
subroutine get_nlines(fn, nlines, stat) !line 9 implicit none !! arguments character(255), intent(in) :: fn integer, intent(out) :: nlines, stat !! local variables character(len=1) :: 1 nlines = 0 open(40, file=fn, status='old') read(40, *, iostat=stat) 1 if (stat /= 0) exit nlines = nlines + 1 end close(40) end subroutine the fortran code stored in src subdirectory of r package, , called with
get_nlines <- function(fn) { stopifnot(file.exists(fn)) res <- .fortran('get_nlines', fn=as.character(fn), nlines=integer(1), stat=integer(1)) if (res$nlines == 0 & res$stat != 0) { warning(paste0('get_nlines did not read lines; iostat error ', res$stat, '.')) return(structure(na, code=res$stat)) } res$nlines } so there is. don't know if fortran code wrong, or if it's occurs on win-builder server.
"i don't know if fortran code wrong" still don't understand question if code have shown "the" code or if inside r package using.
if fortran code speaking (you didn't show else), should try character(*) instead of character(255), because there no apparent reason exact fixed length 255. error message complains about, fn not 255 chars long require in get_nlines().
Comments
Post a Comment