I made a function and I am getting some errors. However, these errors can be overlooked. Is there any function I can use to skip the errors and continue to process the function as is? Thanks!
I made a function with the try statement but i still get an error:
#Function to merge the data with the code descriptions.
myfunction = function(mydata){
##Sets the variables to factors to merge with the code descriptions.
mydata[] <- lapply(mydata, factor)
##Adds "ID" to the end of all the variables to make the merges compatible.
names(mydata) <- paste(names(mydata), "ID", sep = "")
##Uses the dplyr package to make the merges for the variables needed.
try(mydata = mydata %>% left_join(dischargestatuscode, by = "DischargeStatusID") %>% select(-DischargeStatusID, -Code))
try(mydata = mydata %>% left_join(statecode, by = "StateID") %>% select(-StateID, -Code))
try(mydata = mydata %>% left_join(gendercode, by = "GenderID") %>% select(-GenderID, -Code))
try(mydata = mydata %>% left_join(racecode, by = "RaceID") %>% select(-RaceID, -Code))
try(mydata = mydata %>% left_join(agecode, by = "AgeID") %>% select(-AgeID, -Code, -(MinAge:MaxAge)))
try(mydata = mydata %>% left_join(diagnosistypecode, by = "DiagnosisCodeTypeID") %>% select(-DiagnosisCodeTypeID, -Code))
try(mydata = mydata %>% left_join(hcpcscode, by = "HCPCCodeID") %>% select(-HCPCCodeID, -Code))
try(mydata = mydata %>% left_join(countycode, by = "CountyID") %>% select(-CountyID, -Code, -StateID))
try(mydata = mydata %>% left_join(admissionsourcecode, by = "AdmissionSourceID") %>% select(-AdmissionSourceID, -Code))
try(mydata = mydata %>% left_join(admissiontypecode, by = "AdmissionTypeID") %>% select(-AdmissionTypeID, -Code))
try(mydata = mydata %>% left_join(msdrgcodes, by = "ClaimRelatedDRGID") %>%
select(-ClaimRelatedDRGID, -Code, -MdcCategoryID, -type))
try(mydata = mydata %>% left_join(nchpatientstatuscode, by = "NCHPatientStatusID") %>% select(-NCHPatientStatusID, -Code))
##If there is a ICDAccessCode column, the first function works, if there is a ProcedureID column the second function works.
try(mydata = mydata %>% left_join(icd9codes, by = "ICDAccessCodeID") %>%
select(-ICDAccessCodeID, -(ICD9Code:CodeType), -LongDescription))
try(mydata = mydata %>% left_join(icd9codes, by = "ProcedureIDID") %>%
select(-ICDAccessCodeID, -(ICD9Code:CodeType), -LongDescription, -ProcedureIDID, -ICD9Desc))
##Removes the "ID" used for compatbility.
names(mydata) <- gsub("ID", "", names(mydata))
InpatientHistory <<- mydata
}
myfunction(InpatientHistory)
Error I get when i use try:
Error in try(mydata = mydata %>% left_join(dischargestatuscode, by = "DischargeStatusID") %>% :
unused argument (mydata = mydata %>% left_join(dischargestatuscode, by = "DischargeStatusID") %>% select(-DischargeStatusID, -Code))