Coder Social home page Coder Social logo

Comments (2)

tjibbed avatar tjibbed commented on July 26, 2024

I found out it's not exactly the same error that happens for the other variables.

for hospitalID, I get:

Error in get(hospitalID) : object '18091301' not found
where 18091301 is a hospital code

for admDate:

Error: invalid first argument

with traceBack:

  1. stop(err$message, call. = FALSE)
  2. .checkTypos(e, names(x))
  3. value[3L]
  4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
  5. tryCatchList(expr, classes, parentenv, handlers)
  6. tryCatch(eval(.massagei(isub), x, parent.frame()), error = function(e) .checkTypos(e,
    names(x)))
  7. [.data.table(base, get(admDate) > get(disDate), , which = T) at DataManagement.R#302
  8. base[get(admDate) > get(disDate), , which = T] at DataManagement.R#302
  9. checkDates(base = checkResults$base, patientID = patientID, hospitalID = hospitalID,
    admDate = admDate, disDate = disDate, convertDates = convertDates,
    dateFormat = dateFormat, deleteErrors = deleteErrors, verbose = verbose,
    ...) at DataManagement.R#62
  10. checkBase(countryData, deleteMissing = "patient", deleteErrors = "patient",
    convertDates = TRUE, dateFormat = "%y%m%d", patientID = "pID",
    hospitalID = "hID", disDate = "dis", admDate = "admDate",
    verbose = TRUE, maxIteration = 250)

and for disDate the same with traceBack:

  1. stop(err$message, call. = FALSE)
  2. checkTypos(e, names(x))
  3. value[3L]
  4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
  5. tryCatchList(expr, classes, parentenv, handlers)
  6. tryCatch(eval(.massagei(isub), x, parent.frame()), error = function(e) .checkTypos(e,
    names(x)))
  7. [.data.table(base, get(admDate) > get(disDate), , which = T) at DataManagement.R#302
  8. base[get(admDate) > get(disDate), , which = T] at DataManagement.R#302
  9. checkDates(base = checkResults$base, patientID = patientID, hospitalID = hospitalID,
    admDate = admDate, disDate = disDate, convertDates = convertDates,
    dateFormat = dateFormat, deleteErrors = deleteErrors, verbose = verbose,
    ...) at DataManagement.R#62
  10. checkBase(countryData, deleteMissing = "patient", deleteErrors = "patient",
    convertDates = TRUE, dateFormat = "%y%m%d", patientID = "pID",
    hospitalID = "hID", disDate = "disDate", admDate = "adm",
    verbose = TRUE, maxIteration = 250)

from hospitalnetwork.

PascalCrepey avatar PascalCrepey commented on July 26, 2024

Hi Tjibbe,
now :

mydb = create_fake_patientDB(n_patients = 100, n_hospital = 5)
mat1 = hospinet_from_patient_database(base = mydb)

and

setnames(mydb, 1:2, c("patientID", "hospitalID"))
mat2 = hospinet_from_patient_database(base = mydb, patientID = "patientID", hospitalID = "hospitalID")

give the same thing.

The problem was that the resolution of the variables in R is done in multiple context, first the current, and if nothing is found, the parent, etc... Hence the issue can be simplified as:

dt = data.table(a = 1:5)
a = "a"
var = "a"

dt[, get(var)] #works as intended
dt[, get(a)] #fails 

One option to solve this would be to force resolution in the parent environment by deactivating the resolution within the data.table:

dt[, get(var), with = FALSE]
dt[, get(a), with = FALSE]

or use the shorter version ".." which disable nothing but indicate that the variable needs to be looked in the parent environment (hence not in the data.table)

dt[, ..var]
dt[, ..a]

I've implemented the second option in the last commit.

from hospitalnetwork.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.