[R] Evaluation failure of IAPWS95 functions in a rowwise manner (tidyverse style)

Shawn Way SW@y @ending from meco@com
Wed May 30 20:14:13 CEST 2018


I'm trying to use the IAPWS95 package with the tidyverse packages.  For some reason, the function is not outputting the correct rho.

A minimal example with results is below.  I've also included the definition of the DTp function from the IAPWS95 library.  
====================================
library(IAPWS95)
library(tidyverse)

initial <- data.frame(T=c(279,294),p=c(0.46,0.46))
initial2 <- initial %>%
    mutate(rho=DTp(T,p))

> DTp
function (T, p) 
{
    y <- 0
    icode <- 0
    res <- .Fortran("DTp", as.double(T), as.double(p), as.double(y), 
        as.integer(icode))
    options(digits = 9)
    if (res[[4]] != 0) {
        error <- as.character(errorCodes[which(errorCodes[, 1] == 
            res[[4]]), 2])
        print(error)
    }
    print(res[[3]])
}
<bytecode: 0x0000000006f520e0>
<environment: namespace:IAPWS95>

Results:

> initial2
    T    p        rho
1 279 0.46 1000.12283
2 294 0.46 1000.12283


What the results should be:

> initial2
    T    p        rho
1 279 0.46 1000.12283
2 294 0.46 998.19167

I think something is evaluating incorrectly, but I don't know enough about NSE vs SE to figure this out.

Any thoughts to what could be the reason why the second row has the same rho as the first?  When I run the function DTp individually, I get the right results.


Shawn Way

   



More information about the R-help mailing list