Skip to content

Commit

Permalink
fix issue #143
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardszoecs committed Feb 3, 2018
1 parent e46b492 commit afaf416
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ BUG FIXES
* cs_prop() failed when epi-suite data was not available [issue #139, reported and fixed by @stanstrup]
* cs_prop() failed with invalid html [issue #138, reported and fixed by @stanstrup]
* cs_prop() gave incorrect answer, if entries were not available [issue #142, reported and fixed by @stanstrup]
* cs_prop() did not parse scientific number correctly [issue #143, reported by @stanstrup, fixed by @EDiLD]
* is.smiles() failed because of changes in rcdk [PR #140, reported and fixed by @allaway]

DEPRECATED FUNCTIONS
Expand Down
18 changes: 9 additions & 9 deletions R/chemspider.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ cs_prop <- function(csid, verbose = TRUE, ...){

prop <- c(prop, 'Boiling Point')
value_pred <- c(value_pred,
as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+).*',
as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*).*',
'\\1',
ll[grepl('^Boiling Pt \\(deg C', ll)])))
unit_pred <- c(unit_pred, 'deg C')
Expand All @@ -311,15 +311,15 @@ cs_prop <- function(csid, verbose = TRUE, ...){
'\\1',
ll[grepl('^Boiling Pt, ', ll)]))

value_exp <- c(value_exp, save_val(as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+).*',
value_exp <- c(value_exp, save_val(as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*).*',
'\\1',
ll[grepl('^BP \\(exp database', ll)]))))
unit_exp <- c(unit_exp, 'deg C')
source_exp <- c(source_exp, NA)

prop <- c(prop, 'Melting Point')
value_pred <- c(value_pred,
as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+).*',
as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*).*',
'\\1',
ll[grepl('^Melting Pt \\(deg C', ll)])))
unit_pred <- c(unit_pred, 'deg C')
Expand All @@ -336,18 +336,18 @@ cs_prop <- function(csid, verbose = TRUE, ...){
# epi_bp_exp <- as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+).*','\\1', ll[grepl('^BP\\s+\\(exp', ll)]))

prop <- c(prop, 'Water Solubility from KOW')
value_pred <- c(value_pred, as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+).*',
value_pred <- c(value_pred, as.numeric(gsub('.*:\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*).*',
'\\1',
ll[grepl('^Water Solubility at 25 deg C', ll)])))
unit_pred <- c(unit_pred, 'mg/L (25 deg C)')
source_pred <- c(source_pred, gsub('^.*\\((.*)\\)\\:$','\\1',
ll[grepl('^Water Solubility Estimate from Log Kow', ll)]))
value_exp <- c(value_exp,
save_val(as.numeric(gsub('.*=\\s+([-+]?[0-9]*\\.?[0-9]+).*',
save_val(as.numeric(gsub('.*=\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*).*',
'\\1',
ll[grepl('^Water Sol \\(Exper. database match', ll)]))))
unit_exp <- c(unit_exp,
save_val(gsub('.*=\\s+([-+]?[0-9]*\\.?[0-9]+)(.*)',
save_val(gsub('.*=\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*)(.*)',
'\\2',
ll[grepl('^Water Sol \\(Exper. database match', ll)])))
source_exp <- c(source_exp,
Expand All @@ -356,7 +356,7 @@ cs_prop <- function(csid, verbose = TRUE, ...){
ll[which(grepl('^Water Sol \\(Exper. database match', ll)) + 1])))

prop <- c(prop, 'Water Solubility from Fragments')
value_pred <- c(value_pred, as.numeric(gsub('.*=\\s+([-+]?[0-9]*\\.?[0-9]+).*',
value_pred <- c(value_pred, as.numeric(gsub('.*=\\s+([-+]?[0-9]*\\.?[0-9]+[eE]?[-+]?[0-9]*).*',
'\\1',
ll[grepl('^Wat Sol \\(v1.01', ll)])))
unit_pred <- c(unit_pred, 'mg/L')
Expand All @@ -366,10 +366,10 @@ cs_prop <- function(csid, verbose = TRUE, ...){
source_exp <- c(source_exp, NA)

prop <- c(prop, 'Log Octanol-Air Partition Coefficient (25 deg C)')

value_pred_new <- as.numeric(gsub('.*:\\s(.*)', '\\1', ll[grepl('^Log Koa \\(KOAWIN', ll)]))
value_pred <- c(value_pred, ifelse(length(value_pred_new)==0,NA,value_pred_new))

unit_pred <- c(unit_pred, NA)
source_pred <- c(source_pred, gsub('^.*\\[(.*)\\]\\:$',
'\\1',
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-chemspider.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ test_that("cs_prop()", {
expect_is(m4[[1]]$epi, 'data.frame')
expect_is(m4[[1]]$acd, 'data.frame')

# issue #143
r <- m4$`391783`$epi
expect_equal(r$value_pred[r$prop == 'Water Solubility from KOW'], 13690)

})


Expand Down

0 comments on commit afaf416

Please sign in to comment.