-
Notifications
You must be signed in to change notification settings - Fork 4
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
Project object assignment #23
Conversation
R/get_proj.r
Outdated
# not relevant to read all data for running nlmixr in separate session (should be loaded in this session!) | ||
lapply(list.files(paste0(projloc,"/shinyMixR/app/data"),full.names = TRUE),function(x){ | ||
if(!grepl(grepd,x) & !exists(sub("\\.rds$|\\.csv$","",basename(x),ignore.case = TRUE),envir=.GlobalEnv)){ | ||
if(grepl("\\.rds$",x,ignore.case = TRUE)) assign(sub("\\.rds$","",basename(x),ignore.case = TRUE),readRDS(x),pos = .GlobalEnv) | ||
if(grepl("\\.csv$",x,ignore.case = TRUE)) assign(sub("\\.csv$","",basename(x),ignore.case = TRUE),read.csv(x),pos = .GlobalEnv) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RichardHooijmaijers I don't think we need this. I can't find any locations the app where we are pulling the data from the global environment. When we do need this data, we check if it's there, but if it's not, we pull it from the RDS files. So I think we can leave this out. At the same we get rid of the global assignments- they needed to go anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope everything is clear.. Added some comments and pushed quite a lot of changes in this PR. Just have a look and see what you think. For me most things are OK now (especially the main reason for this PR; do not use global assignment). Will add some comments to notion
DESCRIPTION
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why w need magrittr as depend? Seems only %>%
is used and is imported in NAMESPACE, right? Could consider using the base R pipe |>
for this as it only occurs once in the entire code.
was wondering about the license file, saw LICENCE.md is new. Is it default behavior to ad such a file , e.g. is this not apparent when MIT is specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RichardHooijmaijers any packages used in the NAMESPACE must be listed in one of Imports
or Depends
. We can move it to Imports
instead. Using the base pipe is a good idea, but you must be aware of your audience since this reduces backwards compatibility (as it also makes the package only compatibility with R >= 4.1). If that's not a problem I would replace it.
As per R CMD check, we needed the LICENSE.md file. It is not send to CRAN though, it is in .Rbuildignore. You can read more about that here: https://r-pkgs.org/license.html#key-files
R/create_proj.r
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to revise this folder structure. In the end we need the subfolders "analysis", "data", etc. directly in loc
. Noticed the difficulties with this folder structure and found that this is basically caused by the fact that the app was placed in the directory structure, this makes setting the required wd difficult/impossible. Because we don't want the app files in the directory structure, I made a completely new version of run_shinymixr
. This now works with the folder structure and makes everything a lot cleaner
I changed this function also, to reflect mostly the original version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See remark create_proj
, I think the folder structure should be different. Will propose some changes here
inst/dashboard/app.R
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to leave out proj_obj
from top level. I think we will not need it in UI (checked and likely it is used to get model list, which is updated anyway when tab is switched). Will propose some change here
Also this file can be deleted in the end (see run_shinymixr
R/utils.R
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is changed because the way run_shinymixr
is currently setup. At least dry_run
is gone.
NAMESPACE
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some issues with this one... I wanted to add nlmixr2 as import. I was hoping that when running document()
it was automatically added to NAMESPACE. This was not the case, so I added it manually, but was removed when running document
again. I guess I am doing something wrong here but like to briefly discuss this issue (noticed you added manual imports as well, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RichardHooijmaijers the NAMESPACE file should never be edited manually! If you want it to end up there, you need to include it in the roxygen comments of the function that uses the function (at least once in one of your functions), and then run devtools::document()
. Alternatively, if you have things that need to be imported "globally", you can use the shinyMixR-package.R
file for that. If you add new importFrom
statements there, and run devtools::document()
, they also ed up in NAMESPACE.
looks good, let's finish it up! |
I decided to create one app.R file instead of separate ui, server and global files. At the top level of the app.R file, we initiate the proj_obj with:
Then in the ui part we pass along this proj_obj to the modules. This means that the modules all got new arguments.
On the server side we handle it a bit differently. We get the initiated project, and we put it in the petit
r
:throughout the server modules we’ll be referencing
r$proj_obj
, or we will be updating it withr$proj_obj ← get_proj()
The environment stays clean. This is because the top-level of an app.R file is “global” to the Shiny session (and accessible from ui and server), but it doesn’t pollute the user’s global environment. This also means we can get rid of all the assign statements.
Because we’re running a Shiny app in another location, we need to some magic with working directories, so I introduced a
this_wd
variable that sets the working directory to the project folder. We store this inr
too and his is passed along in theget_proj()
function each time.WIP.