{"action":"created","issue":{"url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve/issues/173","repository_url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve","labels_url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve/issues/173/labels{/name}","comments_url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve/issues/173/comments","events_url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve/issues/173/events","html_url":"https://github.com/metrumresearchgroup/mrgsolve/issues/173","id":198295341,"number":173,"title":"[F] Connect data_set, idata_set, and ev with $ENV","user":{"login":"kylebmetrum","id":16908301,"avatar_url":"https://avatars.githubusercontent.com/u/16908301?v=3","gravatar_id":"","url":"https://api.github.com/users/kylebmetrum","html_url":"https://github.com/kylebmetrum","followers_url":"https://api.github.com/users/kylebmetrum/followers","following_url":"https://api.github.com/users/kylebmetrum/following{/other_user}","gists_url":"https://api.github.com/users/kylebmetrum/gists{/gist_id}","starred_url":"https://api.github.com/users/kylebmetrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylebmetrum/subscriptions","organizations_url":"https://api.github.com/users/kylebmetrum/orgs","repos_url":"https://api.github.com/users/kylebmetrum/repos","events_url":"https://api.github.com/users/kylebmetrum/events{/privacy}","received_events_url":"https://api.github.com/users/kylebmetrum/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-01-02T04:38:15Z","updated_at":"2017-01-12T17:28:52Z","closed_at":null,"body":"This was easy to implement and will probably stay as a way to package a data set or event with a model.  \r\n\r\nThe idea is that you can mention a data frame that exists in `$ENV` and use that for `data_set` or `idata_set`.  If you mention a function, the data frame comes from that function call.  You can also specify a `call` argument that is the name of a function in `$ENV` which accepts the data frame as an argument and let's you mess around with it.\r\n\r\n\r\n``` r\r\nknitr::opts_chunk$set(comment='.', message=FALSE)\r\n```\r\n\r\n``` r\r\nlibrary(dplyr)\r\nlibrary(mrgsolve)\r\n\r\n\r\ncode <- '\r\n\r\n$ENV\r\n\r\nidata <- data.frame(ID=1:5)\r\n\r\ne1 <- ev(amt=200,ii=12, addl=3)\r\nd1 <- as.data.frame(e1) %>% mutate(ID=1)\r\n\r\nadd_covs <- function(data,...) {\r\n  data %>%\r\n    dmutate(WT[0,]~ rnorm(55,20)|ID) %>%\r\n    dmutate(SEX ~ binomial(0.5))\r\n}\r\n\r\ndata1 <- function(nid,amt,ii,...) {\r\n  expand.ev(ID=1:nid,amt=amt,ii=ii)\r\n}\r\n\r\n$PARAM CL=1,V=20\r\n$CMT  CENT\r\n$PKMODEL ncmt=1\r\n'\r\n```\r\n\r\n``` r\r\nmod <- mcode(\"test\", code)\r\n```\r\n\r\n``` r\r\nmod %>% idata_set(object=\"idata\") %>% simargs\r\n```\r\n\r\n    . $idata\r\n    .   ID\r\n    . 1  1\r\n    . 2  2\r\n    . 3  3\r\n    . 4  4\r\n    . 5  5\r\n\r\n``` r\r\nmod %>% \r\n  idata_set(object=\"idata\",call=\"add_covs\") %>% \r\n  simargs\r\n```\r\n\r\n    . $idata\r\n    .   ID       WT SEX\r\n    . 1  1 60.12401   1\r\n    . 2  2 56.61977   0\r\n    . 3  3 28.64610   0\r\n    . 4  4 35.59545   0\r\n    . 5  5 61.05005   1\r\n\r\n``` r\r\nmod %>% \r\n  data_set(object=\"data1\",nid=10,amt=c(50,100),ii=24) %>%  \r\n  simargs \r\n```\r\n\r\n    . $data\r\n    .       ID amt ii evid cmt time ..zeros..\r\n    .  [1,]  1  50 24    1   1    0         0\r\n    .  [2,]  2  50 24    1   1    0         0\r\n    .  [3,]  3  50 24    1   1    0         0\r\n    .  [4,]  4  50 24    1   1    0         0\r\n    .  [5,]  5  50 24    1   1    0         0\r\n    .  [6,]  6  50 24    1   1    0         0\r\n    .  [7,]  7  50 24    1   1    0         0\r\n    .  [8,]  8  50 24    1   1    0         0\r\n    .  [9,]  9  50 24    1   1    0         0\r\n    . [10,] 10  50 24    1   1    0         0\r\n    . [11,] 11 100 24    1   1    0         0\r\n    . [12,] 12 100 24    1   1    0         0\r\n    . [13,] 13 100 24    1   1    0         0\r\n    . [14,] 14 100 24    1   1    0         0\r\n    . [15,] 15 100 24    1   1    0         0\r\n    . [16,] 16 100 24    1   1    0         0\r\n    . [17,] 17 100 24    1   1    0         0\r\n    . [18,] 18 100 24    1   1    0         0\r\n    . [19,] 19 100 24    1   1    0         0\r\n    . [20,] 20 100 24    1   1    0         0\r\n    . attr(,\"class\")\r\n    . [1] \"mrgindata\"\r\n\r\n``` r\r\nmod %>% ev(object=\"e1\") %>% mrgsim\r\n```\r\n\r\n    . Model:  test.cpp \r\n    . Dim:    26 x 3 \r\n    . Time:   0 to 24 \r\n    . ID:     1 \r\n    .      ID time  CENT\r\n    . [1,]  1    0   0.0\r\n    . [2,]  1    0 200.0\r\n    . [3,]  1    1 190.2\r\n    . [4,]  1    2 181.0\r\n    . [5,]  1    3 172.1\r\n    . [6,]  1    4 163.7\r\n    . [7,]  1    5 155.8\r\n    . [8,]  1    6 148.2\r\n"},"comment":{"url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve/issues/comments/272227266","html_url":"https://github.com/metrumresearchgroup/mrgsolve/issues/173#issuecomment-272227266","issue_url":"https://api.github.com/repos/metrumresearchgroup/mrgsolve/issues/173","id":272227266,"user":{"login":"kylebmetrum","id":16908301,"avatar_url":"https://avatars.githubusercontent.com/u/16908301?v=3","gravatar_id":"","url":"https://api.github.com/users/kylebmetrum","html_url":"https://github.com/kylebmetrum","followers_url":"https://api.github.com/users/kylebmetrum/followers","following_url":"https://api.github.com/users/kylebmetrum/following{/other_user}","gists_url":"https://api.github.com/users/kylebmetrum/gists{/gist_id}","starred_url":"https://api.github.com/users/kylebmetrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylebmetrum/subscriptions","organizations_url":"https://api.github.com/users/kylebmetrum/orgs","repos_url":"https://api.github.com/users/kylebmetrum/repos","events_url":"https://api.github.com/users/kylebmetrum/events{/privacy}","received_events_url":"https://api.github.com/users/kylebmetrum/received_events","type":"User","site_admin":false},"created_at":"2017-01-12T17:28:51Z","updated_at":"2017-01-12T17:28:51Z","body":"The other issue is documentation of what's in `$ENV`.  It seems like the user could do this in `$PROB`.  I don't know if there really needs to be a formal structure to it, but maybe start encouraging that sort of documentation and a function to return the text in `$PROB`.  Obviously we could also render the model, but that might be too much to ask on a routine basis.  "}}
{"actor":{"display_login":"kylebmetrum"}}