hodgesse1 / rfortran

Automatically exported from code.google.com/p/rfortran
0 stars 0 forks source link

Retrieve R warnings to R message log #54

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
*** Please provide a description of the enhancement you are requesting.

Currently, only R errors are passed back to the message log, better to also 
include warnings.

Here is some sample code to do this, though there are problems extracting 
the warnings()

recursive function Reval(command,checkWarn) result(ok)

      ! Description: Evaluates a command - does not provide any return 
values other than the error flag
      use rdcom, only: $IStatConnector_EvaluateNoReturn
      implicit none
      character(*), intent(in) :: command     ! command to pass in to R
      logical(mlk), intent(in), optional :: CheckWarn
      integer(mik) :: ok                    ! error flag - 0 is ok
      logical(mlk) :: checkWarnLc,newWarn,checkWarnDef=.true.
      checkWarnLc=checkPresent(checkWarn,checkWarnDef)
      if (.not.check_initialised()) then; ok=-1; return; end if 
      ! Set check for warnings      
      if(checkWarnLc) 
ok=Reval("nwarn1=length(last.warning)",checkWarn=.false.)

      ok = $IStatConnector_EvaluateNoReturn(R, command)
      if(ok/=0) call message("Reval failed: "//trim(command)//"\n"C//"R 
"//Rgeterrormessage(),msg_id=ok,db_id="RFORTRAN")

      ! check for warnings and return if new warining
      if(checkWarnLc) then
        ok=Reval("nwarn2=length(last.warning)",checkWarn=.false.)
        ok=Rget("(nwarn2>nwarn1)",newwarn)
        if (newwarn) call message(log_warn,"R 
Warning:"//trim(Rgetlastwarning()))
        ok=Reval("rm(nwarn1,newwarn2);gc()",checkWarn=.false.)
      end if  
    end function

Original issue reported on code.google.com by mark.th...@gmail.com on 19 Feb 2010 at 5:59

GoogleCodeExporter commented 8 years ago

Original comment by mark.th...@gmail.com on 19 Feb 2010 at 5:59

GoogleCodeExporter commented 8 years ago

Original comment by mark.th...@gmail.com on 14 Feb 2011 at 11:06