nlmixr2 / rxode2

rxode2
https://nlmixr2.github.io/rxode2/
GNU General Public License v3.0
29 stars 7 forks source link

Adding dosing when id is character only adds entry to subject 1 #723

Open john-harrold opened 10 months ago

john-harrold commented 10 months ago

I was trying to create an event table programmatically. My subject ids were cast as a character. I'm recreating that effect below with as.chacter(). When I created the dosing like below everything just went into the first compartment:

library(rxode2et)
sub_ids = c(1,2,3,4,5)

# creating observations
obs_times = c(0:20)
events = et(time=obs_times, id=sub_ids)

for(sub_id in sub_ids){
  events = etRbind(
    events, 
    # This does not work
    et(cmt = "Ac", amt=c(1,1,1), time = c(0, 1, 2), id=as.character(sub_id)))
}
image

However this works fine:

rm(list=ls())

library(rxode2et)
sub_ids = c(1,2,3,4,5)

# creating observations
obs_times = c(0:20)
events = et(time=obs_times, id=sub_ids)

for(sub_id in sub_ids){
  events = etRbind(
    events, 
    # This works 
      et(cmt = "Ac", amt=c(1,1,1), time = c(0, 1, 2), id=sub_id))
}
image

I think it should either convert ids to numeric values or fail with an error.

mattfidler commented 10 months ago

Probably should error with an error