@@ -253,7 +253,7 @@ poso_time_cmin <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
253253 cmin_ppk_model [,endpoint ] < target_cmin ,
254254 ]$ time ) - time_last_dose
255255 # here cmin_distribution is a point estimate of the endpoint
256- cmin_distribution << -
256+ cmin_distribution <-
257257 cmin_ppk_model [cmin_ppk_model $ time == (time_to_target +
258258 time_last_dose ),endpoint ]
259259 }
@@ -386,6 +386,9 @@ poso_dose_auc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
386386
387387 object <- posologyr(prior_model ,dat ,nocb )
388388
389+ # initialization of conc_distribution to avoid a global variable
390+ auc_distribution <- 0
391+
389392 if (tdm ){ # using TDM data
390393 # input validation
391394 if (is.null(time_dose )){
@@ -448,13 +451,12 @@ poso_dose_auc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
448451 ifelse(nocb ," nocb" ," locf" ))
449452
450453 auc_proposal <- max(auc_ppk_model $ AUC )- min(auc_ppk_model $ AUC )
451- auc_distribution <<- auc_proposal # to parent environment
454+ p <- parent.frame()
455+ p $ auc_distribution <- auc_proposal
452456 # return the difference between the computed auc and the target
453457 delta_auc <- (target_auc - auc_proposal )^ 2
454458 return (delta_auc )
455459 }
456- # initialization of conc_distribution to avoid a global variable
457- auc_distribution <- 0
458460
459461 optim_dose_auc <- stats :: optim(starting_dose ,err_dose_tdm ,
460462 time_dose = time_dose ,target_auc = target_auc ,
@@ -525,7 +527,8 @@ poso_dose_auc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
525527 auc_index <- ceiling(p * n_auc )
526528
527529 # assign the distribution of auc to the parent environment
528- auc_distribution <<- sorted_auc
530+ p <- parent.frame()
531+ p $ auc_distribution <- sorted_auc
529532
530533 if (greater_than ){
531534 auc_proposal <- sorted_auc [n_auc - auc_index ]
@@ -534,7 +537,8 @@ poso_dose_auc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
534537 }
535538 } else {
536539 auc_proposal <- max(auc_ppk_model $ AUC )- min(auc_ppk_model $ AUC )
537- auc_distribution <<- auc_proposal
540+ p <- parent.frame()
541+ p $ auc_distribution <- auc_proposal
538542 }
539543
540544 # return the difference between the computed AUC and the target
@@ -739,7 +743,8 @@ poso_dose_conc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
739743 ifelse(nocb ," nocb" ," locf" ))
740744
741745 conc_proposal <- ctime_ppk_model [,endpoint ]
742- conc_distribution <<- conc_proposal # to parent environment
746+ p <- parent.frame()
747+ p $ conc_distribution <- conc_proposal
743748 # return the difference between the computed ctime and the target
744749 delta_conc <- (target_conc - conc_proposal )^ 2
745750 return (delta_conc )
@@ -803,7 +808,8 @@ poso_dose_conc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
803808 conc_index <- ceiling(p * n_conc )
804809
805810 # assign the distribution of concentrations to the parent environment
806- conc_distribution <<- sorted_conc
811+ p <- parent.frame()
812+ p $ conc_distribution <- sorted_conc
807813
808814 if (greater_than ){
809815 conc_proposal <- sorted_conc [n_conc - conc_index ]
@@ -812,7 +818,8 @@ poso_dose_conc <- function(dat=NULL,prior_model=NULL,tdm=FALSE,
812818 }
813819 } else {
814820 conc_proposal <- ctime_ppk_model [,endpoint ]
815- conc_distribution <<- conc_proposal
821+ p <- parent.frame()
822+ p $ conc_distribution <- conc_proposal
816823 }
817824
818825 # return the difference between the computed ctime and the target
@@ -979,7 +986,8 @@ poso_inter_cmin <- function(dat=NULL,prior_model=NULL,dose,target_cmin,
979986 cmin_index <- ceiling(p * n_cmin )
980987
981988 # assign the distribution of cmin to the parent environment
982- cmin_distribution <<- sorted_cmin
989+ p <- parent.frame()
990+ p $ cmin_distribution <- sorted_cmin
983991
984992 if (greater_than ){
985993 cmin_proposal <- sorted_cmin [n_cmin - cmin_index ]
@@ -988,7 +996,8 @@ poso_inter_cmin <- function(dat=NULL,prior_model=NULL,dose,target_cmin,
988996 }
989997 } else {
990998 cmin_proposal <- cmin_ppk_model [,endpoint ]
991- cmin_distribution <<- cmin_proposal
999+ p <- parent.frame()
1000+ p $ cmin_distribution <- cmin_proposal
9921001 }
9931002
9941003 # return the difference between the computed cmin and the target,
0 commit comments