Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with setting up omega with a vector variable #16

Open
snailittle opened this issue May 18, 2021 · 1 comment
Open

issue with setting up omega with a vector variable #16

snailittle opened this issue May 18, 2021 · 1 comment

Comments

@snailittle
Copy link

I tried to save the omega values into vector and use that in "lotri" to set up the omega, which caused an error. Please see below. I can't explicitly write out the omega as usually done because I am implementing it in shiny, and it will have to be passed around with a vector

the usual way which works:

omega<- lotri(eta.KA+eta.CL+eta.V2+eta.Q+eta.V3~c(0.1,
0,0.1,
0,0.06,0.1,
0,0.04,0.04,0.1,
0,0.02,0.02,0.04,0.1))

My way which didn't work

etacov=c(0.1,
0,0.1,
0,0.06,0.1,
0,0.04,0.04,0.1,
0,0.02,0.02,0.04,0.1)
omega <- lotri(eta.KA+eta.CL+eta.V2+eta.Q+eta.V3~ etacov)
Error in dimnames(.ret) <- list(.env$names, .env$names) :
length of 'dimnames' [1] not equal to array extent

@mattfidler mattfidler transferred this issue from nlmixrdevelopment/RxODE May 18, 2021
@mattfidler
Copy link
Contributor

mattfidler commented May 18, 2021

I can reproduce this issue:

library(lotri)
etacov=c(0.1,
          0,0.1,
          0,0.06,0.1,
          0,0.04,0.04,0.1,
          0,0.02,0.02,0.04,0.1)
omega <- lotri(eta.KA+eta.CL+eta.V2+eta.Q+eta.V3~ etacov)
#> Error in dimnames(.ret) <- list(env$names, env$names): length of 'dimnames' [1] not equal to array extent

Created on 2021-05-18 by the reprex package (v2.0.0)

I believe this is because lotri uses nonstandard evaluation and this isn't supported yet. You could always use the following instead:

library(lotri)
library(backports)
etacov=c(0.1,
          0,0.1,
          0,0.06,0.1,
          0,0.04,0.04,0.1,
          0,0.02,0.02,0.04,0.1)
omega <- eval(parse(text=paste0("lotri(eta.KA+eta.CL+eta.V2+eta.Q+eta.V3~",
                deparse1(etacov), ")")))

omega
#>        eta.KA eta.CL eta.V2 eta.Q eta.V3
#> eta.KA    0.1   0.00   0.00  0.00   0.00
#> eta.CL    0.0   0.10   0.06  0.04   0.02
#> eta.V2    0.0   0.06   0.10  0.04   0.02
#> eta.Q     0.0   0.04   0.04  0.10   0.04
#> eta.V3    0.0   0.02   0.02  0.04   0.10

Created on 2021-05-18 by the reprex package (v2.0.0)

This reprex requires R 4.0 or a recent version of backports. If you don't have either you can define deparse1 manually as:

deparse1 <-function (expr, collapse = " ", width.cutoff = 500L, ...)  {
  paste(deparse(expr, width.cutoff, ...), collapse = collapse)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants