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.6.0
CoolProp gitrevision:   ba21c74fd1c3a4934bbecbf459936983dec424c2
CoolProp Fluids:   n-Nonane,MethylLinolenate,DimethylCarbonate,R21,DiethylEther,trans-2-Butene,R245fa,ParaDeuterium,OrthoDeuterium,Isohexane,R365MFC,n-Dodecane,R410A,Deuterium,D4,R13,MD2M,n-Hexane,Methane,Ethane,CarbonylSulfide,EthylBenzene,CarbonMonoxide,Isopentane,Xenon,cis-2-Butene,R152A,Oxygen,EthyleneOxide,R1234ze(E),n-Octane,R404A,R236EA,CycloHexane,n-Heptane,R22,R113,n-Pentane,MethylLinoleate,R11,SulfurDioxide,R23,Helium,R32,R227EA,R407C,HydrogenSulfide,Air,R245ca,Novec649,R143a,D5,R507A,R134a,Dichloroethane,ParaHydrogen,R1233zd(E),Acetone,n-Decane,HeavyWater,MethylPalmitate,n-Propane,R115,R1234yf,R236FA,Ethylene,R116,MD4M,Benzene,Methanol,SulfurHexafluoride,o-Xylene,R125,Fluorine,R1234ze(Z),CarbonDioxide,IsoButane,n-Butane,NitrousOxide,DimethylEther,RC318,Toluene,IsoButene,MethylStearate,Ammonia,Argon,R218,R41,Neon,Propyne,CycloPropane,R12,Nitrogen,Water,MethylOleate,R161,D6,SES36,HFE143m,n-Undecane,R123,HydrogenChloride,m-Xylene,R141b,R124,1-Butene,Propylene,R14,p-Xylene,Cyclopentane,MDM,Hydrogen,Neopentane,Ethanol,OrthoHydrogen,R114,Krypton,MD3M,R1243zf,MM,R142b,R40,R13I1
*********** 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:   10.0
Critical temperature of water:   647.096   K
Boiling temperature of water at 101325 Pa:   373.124295847701   K
c_p of water at 101325 Pa and 300 K:   4180.63577657559   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.272980171265   K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
NULL
NULL
Vapor molar density:   0.441465626653878   mol/m^3
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”