From da13d9e857dd29e12d9bfdb3e1044014fa48537b Mon Sep 17 00:00:00 2001 From: Tianshu Chen Date: Wed, 8 Jul 2020 06:02:12 -0600 Subject: [PATCH] v1.0.2 updated ofp preventing error in match CAS. --- DESCRIPTION | 2 +- R/ofp.R | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 60d1334..573d813 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: foqat Type: Package Title: Field observation quick analysis tookit -Version: 1.0.1 +Version: 1.0.2 Author: Tianshu Chen Maintainer: Tianshu Chen Description: A quick analysis toolkits for atmospheric field observation. diff --git a/R/ofp.R b/R/ofp.R index 07a9d0f..c22b565 100644 --- a/R/ofp.R +++ b/R/ofp.R @@ -29,6 +29,8 @@ ofp <- function(df, unit = "ugm", t = 25, p = 101.325, colid = 1){ colnm_df = colnames(df)[2:ncol(df)] chemicalnames = ifelse(substr(colnm_df, 1, 1) == "X", sub("^.", "", colnm_df), colnm_df) chemicalnames = gsub("\\.", "-", chemicalnames) + #if i- + chemicalnames = gsub("\\i-", "iso-", chemicalnames) #build name_df name_df = data.frame(name = chemicalnames,CAS = NA, Source = NA, Matched_Name = NA, MIR = NA, MW = NA, stringsAsFactors = FALSE) @@ -47,6 +49,9 @@ ofp <- function(df, unit = "ugm", t = 25, p = 101.325, colid = 1){ }else if(result_test[2] == "Search Results"){ name_df[i,2]="More than 1 result" name_df[i,3]="" + }else if(grepl("structure unspecified",result_test[2])){ + name_df[i,2]="structure unspecified in NIST" + name_df[i,3]="" }else{ result_test<-web%>%html_nodes("li")%>%html_text() result_test<-strsplit(result_test[21], ": ") @@ -57,11 +62,11 @@ ofp <- function(df, unit = "ugm", t = 25, p = 101.325, colid = 1){ #match mir by different sources ##by NIST - a=lapply(name_df$CAS[which(name_df$Source=="NIST")], function(i) grep(i, datacas$`CAS`)) + a=lapply(name_df$CAS[which(name_df$Source=="NIST"&!is.na(name_df$CAS))], function(i) grep(i, datacas$CAS)) a=unlist(lapply(a,function(x) if(identical(x,integer(0))) ' ' else x)) - name_df$MIR[which(name_df$Source=="NIST")] = datacas$New[as.numeric(a)] - name_df$Matched_Name[which(name_df$Source=="NIST")] = datacas$Description[as.numeric(a)] - name_df$MW[which(name_df$Source=="NIST")] = datacas$MWt[as.numeric(a)] + name_df$MIR[which(name_df$Source=="NIST"&!is.na(name_df$CAS))] = datacas$New[as.numeric(a)] + name_df$Matched_Name[which(name_df$Source=="NIST"&!is.na(name_df$CAS))] = datacas$Description[as.numeric(a)] + name_df$MW[which(name_df$Source=="NIST"&!is.na(name_df$CAS))] = datacas$MWt[as.numeric(a)] for(k in which(name_df$Source=="")){ tarlist=gsub(" ", "", tolower(datacas$Description), fixed = TRUE)