R Under development (unstable) (2025-01-11 r87563 ucrt) -- "Unsuffered Consequences"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> # R CMD BATCH --no-timing --no-restore --no-save unit_test.R unit_test.Rout
> 
> # Get rid of anything in the workspace:
> rm(list=ls()) 
> 
> library(httk)
> #
> # MW BPA is 228.29 g/mol
> # 1 mg/L -> 1/228.29*1000 = 4.38 uM
> convert_units("mg/L","uM",chem.cas="80-05-7")
[1] 4.38
> #
> # MW Diclofenac is 296.148 g/mol
> # 1 uM -> 296.148/1000 =  0.296
> convert_units("uM","mg/L",chem.name="diclofenac")
[1] 0.2962
> 
> #
> # Compare with 
> #   https://www.eurofinsus.com/environment-testing/services/air-and-vapor/unit-conversion-calculator/
> # STP assumes 24.45 = (25?C and 1 atm)
> # 1 ug/L Toluene -> 0.26539 ppmv
> convert_units("ug/L","ppmv",
+                 chem.name="toluene",
+                 state="gas")
[1] 0.2655
> #
> # 1 ppmv Toluene -> 0.0038 mg/L
> convert_units("ppmv","mg/L",
+               chem.name="toluene",
+               state="gas")
[1] 0.003766
> # 1 ug/L Styrene ->  0.23478 ppmv
> convert_units("ug/L","ppmv",
+                 chem.name="styrene",
+                 state="gas")
[1] 0.2348
>                 
> # Test that convert_solve_x doesn't throw any errors:
> signif(head(solve_gas_pbtk(chem.name="bisphenol a",
+                     times=c(0,0.1,0.05),
+                     output.units=setNames("mg/m3","Cendexhppmv"),
+                     method = "lsode",
+                     mf = 10, 
+                     rtol=1e-7,
+                     atol=1e-7)), 2)
            output.unit conversion.factor
Cendexhppmv       mg/m3             9.332
AUC is area under the plasma concentration curve in uM*days units with Rblood2plasma = 0.795.
The model outputs are provided in the following units:
	uM: Cgut, Cliver, Cven, Clung, Cart, Crest, Ckidney, Cplasma, Cmuc
	ppmv: Calvppmv, Cmixexhppmv
	mg/m3: Cendexhppmv
	umol: Atubules, Ametabolized
	uM*days: AUC

      time    Cgut  Cliver    Cven   Clung   Cart   Crest Ckidney Cplasma
[1,] 0e+00 0.00000 0.0e+00 0.0e+00 0.00000 0.0000 0.0e+00  0.0000 0.0e+00
[2,] 1e-04 0.00046 7.7e-05 1.8e-06 0.00012 0.0058 2.2e-05  0.0018 2.3e-06
[3,] 5e-02 0.59000 1.4e-01 1.7e-02 0.29000 0.0390 1.0e-01  0.9400 2.1e-02
[4,] 1e-01 0.74000 1.8e-01 2.5e-02 0.39000 0.0480 2.0e-01  1.2000 3.1e-02
     Calvppmv Cendexhppmv Cmixexhppmv   Cmuc Atubules Ametabolized     AUC
[1,]    0e+00     0.00000        0.30    0.0  0.0e+00      0.0e+00 0.00000
[2,]    0e+00     0.00016        0.30    3.7  1.7e-06      1.2e-06 0.00000
[3,]    1e-07     0.07400        0.31 1800.0  9.2e-03      2.2e+00 0.00069
[4,]    2e-07     0.15000        0.31 3600.0  2.1e-02      5.8e+00 0.00200
Warning messages:
1: In solve_model(chem.name = chem.name, chem.cas = chem.cas, dtxsid = dtxsid,  :
  Value FALSE for restrictive.clearance in parameterze.arg.list has overwritting value TRUE in arguments to solve.model.
2: In get_clint(dtxsid = dtxsid, chem.name = chem.name, chem.cas = chem.cas,  :
  Clint is provided as a distribution.
3: In apply_clint_adjustment(Clint.point, Fu_hep = Fu_hep, suppress.messages = suppress.messages) :
  Clint adjusted for in vitro partitioning (Kilford, 2008), see calc_hep_fu.
4: In parameterize_gas_pbtk(chem.cas = "80-05-7", chem.name = "bisphenol a",  :
  Funbound.plasma adjusted for in vitro partitioning (Pearce, 2017). Set adjusted.Funbound.plasma to FALSE to use original value.
5: In parameterize_gas_pbtk(chem.cas = "80-05-7", chem.name = "bisphenol a",  :
  Cannot calculate saturable metabolism with Vmax = 0. Defaulting to first-order metabolic clearance.
6: In get_caco2(chem.cas = chem.cas, chem.name = chem.name, dtxsid = dtxsid,  :
  Default value of 1.6 used for Caco2 permeability.
> 
> # Quit without saving or displaying messages:
> quit("no")
> proc.time()
   user  system elapsed 
   3.06    0.23    3.28