R Wrapper

Pre-compiled Binaries

Pre-compiled binaries can be downloaded from R. Development binaries coming from the buildbot server can be found at R. Download the shared library for your platform, as well as the CoolProp.R module

Usage

At the R console, run:

dyn.load(paste("CoolProp", .Platform$dynlib.ext, sep=""))
source("CoolProp.R")
cacheMetaData(1)
PropsSI("T","P",101325,"Q",0,"Water")

There is example code at the end of this page

Warning

For OSX users that wish to call REFPROP, you may be required to set the environmental variable DYLD_LIBRARY_PATH to the folder containing your REFPROP.dylib shared library, which is probably /opt/refprop

Warning

If you want to use Rscript rather than R, you need to pass the argument --default-packages=methods to get it to load the necessary packages for calling SWIGG-ed code. Or call library(methods) at the top of the file (before source("CoolProp.R")). See also http://stackoverflow.com/a/19468533n

User-Compiled Binaries

Common Requirements

Compilation of the R wrapper requires a few common wrapper pre-requisites

Also, you need to install R

Windows

You must install the MINGW compiler suite. The TDM suite is recommended.

Build

Linux and OSX

Once the dependencies are installed, you can run the builder and tests using:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
mkdir -p  CoolProp/build && cd CoolProp/build
# Build the makefile using CMake
cmake .. -DCOOLPROP_R_MODULE=ON -DR_BIN="/usr/bin" -DCMAKE_BUILD_TYPE=Release
# Make the R shared library
cmake --build .

Windows (32-bit and 64-bit)

You need to just slightly modify the building procedure:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Make a build folder
mkdir build && cd build
# Build the makefile using CMake (Must use MINGW since R is built with MINGW)
cmake .. -DCOOLPROP_R_MODULE=ON -G "MinGW Makefiles" -DR_BIN="c:\Program Files\R\R-3.2.1\bin\x64" -DCMAKE_BUILD_TYPE=Release
# Make the R shared library
cmake --build .

Example Code

dyn.load(paste("CoolProp", .Platform$dynlib.ext, sep=""))
library(methods) # See http://stackoverflow.com/a/19468533
source("CoolProp.R")
cacheMetaData(1)
writeLines(paste('**************** INFORMATION ***************'))
writeLines(paste('This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell'))
writeLines(paste('CoolProp version:', ' ', get_global_param_string('version')))
writeLines(paste('CoolProp gitrevision:', ' ', get_global_param_string('gitrevision')))
writeLines(paste('CoolProp Fluids:', ' ', get_global_param_string('FluidsList')))
# See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface
writeLines(paste('*********** HIGH LEVEL INTERFACE *****************'))
writeLines(paste('Critical temperature of water:', ' ', Props1SI('Water', 'Tcrit'), ' ', 'K'))
writeLines(paste('Boiling temperature of water at 101325 Pa:', ' ', PropsSI('T', 'P', 101325, 'Q', 0, 'Water'), ' ', 'K'))
writeLines(paste('Phase of water at 101325 Pa and 300 K:', ' ', PhaseSI('P', 101325, 'T', 300, 'Water')))
writeLines(paste('c_p of water at 101325 Pa and 300 K:', ' ', PropsSI('C', 'P', 101325, 'T', 300, 'Water'), ' ', 'J/kg/K'))
writeLines(paste('c_p of water (using derivatives) at 101325 Pa and 300 K:', ' ', PropsSI('d(H)/d(T)|P', 'P', 101325, 'T', 300, 'Water'), ' ', 'J/kg/K'))
writeLines(paste('*********** HUMID AIR PROPERTIES *****************'))
writeLines(paste('Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:', ' ', HAPropsSI('W', 'T', 300, 'P', 101325, 'R', 0.5), ' ', 'kg_w/kg_da'))
writeLines(paste('Relative humidity from last calculation:', ' ', HAPropsSI('R', 'T', 300, 'P', 101325, 'W', HAPropsSI('W', 'T', 300, 'P', 101325, 'R', 0.5)), ' ', '(fractional)'))
writeLines(paste('*********** INCOMPRESSIBLE FLUID AND BRINES *****************'))
writeLines(paste('Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:', ' ', PropsSI('D', 'T', 300, 'P', 101325, 'INCOMP::MEG-50%'), ' ', 'kg/m^3'))
writeLines(paste('Viscosity of Therminol D12 at 350 K, 101325 Pa:', ' ', PropsSI('V', 'T', 350, 'P', 101325, 'INCOMP::TD12'), ' ', 'Pa-s'))
# If you don't have REFPROP installed, disable the following lines
writeLines(paste('*********** REFPROP *****************'))
writeLines(paste('REFPROP version:', ' ', get_global_param_string('REFPROP_version')))
writeLines(paste('Critical temperature of water:', ' ', Props1SI('REFPROP::Water', 'Tcrit'), ' ', 'K'))
writeLines(paste('Boiling temperature of water at 101325 Pa:', ' ', PropsSI('T', 'P', 101325, 'Q', 0, 'REFPROP::Water'), ' ', 'K'))
writeLines(paste('c_p of water at 101325 Pa and 300 K:', ' ', PropsSI('C', 'P', 101325, 'T', 300, 'REFPROP::Water'), ' ', 'J/kg/K'))
writeLines(paste('*********** TABULAR BACKENDS *****************'))
TAB = AbstractState_factory('BICUBIC&HEOS', 'R245fa')
TAB$update("PT_INPUTS", 101325, 300)
writeLines(paste('Mass density of refrigerant R245fa at 300 K, 101325 Pa:', ' ', TAB$rhomass(), ' ', 'kg/m^3'))
writeLines(paste('*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************'))
AS_SAT = AbstractState_factory('HEOS', 'R245fa')
AS_SAT$update("PQ_INPUTS", 101325, 0)
writeLines(paste('First saturation derivative:', ' ', AS_SAT$first_saturation_deriv("iP", "iT"), ' ', 'Pa/K'))
writeLines(paste('*********** LOW-LEVEL INTERFACE *****************'))
AS = AbstractState_factory('HEOS', 'Water&Ethanol')
z = c(0.5, 0.5)
AS$set_mole_fractions(z)
AS$update("PQ_INPUTS", 101325, 1)
writeLines(paste('Normal boiling point temperature of water and ethanol:', ' ', AS$T(), ' ', 'K'))
# If you don't have REFPROP installed, disable the following block
writeLines(paste('*********** LOW-LEVEL INTERFACE (REFPROP) *****************'))
AS2 = AbstractState_factory('REFPROP', 'Methane&Ethane')
z2 = c(0.2, 0.8)
AS2$set_mole_fractions(z2)
AS2$update("QT_INPUTS", 1, 120)
writeLines(paste('Vapor molar density:', ' ', AS2$keyed_output("iDmolar"), ' ', 'mol/m^3'))

Example Code Output

**************** INFORMATION ***************
This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell
CoolProp version:   6.1.0
CoolProp gitrevision:   7864c2614ce5a0ef972386ee7f39859f0d3f8038
CoolProp Fluids:   1-Butene,Acetone,Air,Ammonia,Argon,Benzene,CarbonDioxide,CarbonMonoxide,CarbonylSulfide,cis-2-Butene,CycloHexane,Cyclopentane,CycloPropane,D4,D5,D6,Deuterium,Dichloroethane,DiethylEther,DimethylCarbonate,DimethylEther,Ethane,Ethanol,EthylBenzene,Ethylene,EthyleneOxide,Fluorine,HeavyWater,Helium,HFE143m,Hydrogen,HydrogenChloride,HydrogenSulfide,IsoButane,IsoButene,Isohexane,Isopentane,Krypton,m-Xylene,MD2M,MD3M,MD4M,MDM,Methane,Methanol,MethylLinoleate,MethylLinolenate,MethylOleate,MethylPalmitate,MethylStearate,MM,n-Butane,n-Decane,n-Dodecane,n-Heptane,n-Hexane,n-Nonane,n-Octane,n-Pentane,n-Propane,n-Undecane,Neon,Neopentane,Nitrogen,NitrousOxide,Novec649,o-Xylene,OrthoDeuterium,OrthoHydrogen,Oxygen,p-Xylene,ParaDeuterium,ParaHydrogen,Propylene,Propyne,R11,R113,R114,R115,R116,R12,R123,R1233zd(E),R1234yf,R1234ze(E),R1234ze(Z),R124,R125,R13,R134a,R13I1,R14,R141b,R142b,R143a,R152A,R161,R21,R218,R22,R227EA,R23,R236EA,R236FA,R245ca,R245fa,R32,R365MFC,R40,R404A,R407C,R41,R410A,R507A,RC318,SES36,SulfurDioxide,SulfurHexafluoride,Toluene,trans-2-Butene,Water,Xenon
*********** HIGH LEVEL INTERFACE *****************
Critical temperature of water:   647.096   K
Boiling temperature of water at 101325 Pa:   373.124295847684   K
Phase of water at 101325 Pa and 300 K:   liquid
c_p of water at 101325 Pa and 300 K:   4180.63577655607   J/kg/K
c_p of water (using derivatives) at 101325 Pa and 300 K:   4180.63577655607   J/kg/K
*********** HUMID AIR PROPERTIES *****************
Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:   0.0110955297051998   kg_w/kg_da
Relative humidity from last calculation:   0.5   (fractional)
*********** INCOMPRESSIBLE FLUID AND BRINES *****************
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:   1061.17930772046   kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa:   0.000522883799095536   Pa-s
*********** REFPROP *****************
REFPROP version:   9.1.1.10
Critical temperature of water:   647.096   K
Boiling temperature of water at 101325 Pa:   373.124295847699   K
c_p of water at 101325 Pa and 300 K:   4180.63577657788   J/kg/K
*********** TABULAR BACKENDS *****************
NULL
Mass density of refrigerant R245fa at 300 K, 101325 Pa:   5.64812825704638   kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
NULL
First saturation derivative:   4058.51975505072   Pa/K
*********** LOW-LEVEL INTERFACE *****************
NULL
NULL
Normal boiling point temperature of water and ethanol:   357.272980172343   K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
NULL
NULL
Vapor molar density:   0.441465625159452   mol/m^3
Creating a generic function for ‘print’ from package ‘base’ in the global environment
in method for ‘copyToR’ with signature ‘"_p_CoolProp::SimpleState"’: no definition for class “_p_CoolProp::SimpleState”
in method for ‘copyToR’ with signature ‘"_p_CoolProp::CriticalState"’: no definition for class “_p_CoolProp::CriticalState”
in method for ‘copyToR’ with signature ‘"_p_CoolProp::SsatSimpleState"’: no definition for class “_p_CoolProp::SsatSimpleState”