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

Permissions for writemrgsolve #37

Closed
Andy00000000000 opened this issue Nov 14, 2024 · 7 comments
Closed

Permissions for writemrgsolve #37

Andy00000000000 opened this issue Nov 14, 2024 · 7 comments

Comments

@Andy00000000000
Copy link
Owner

Dear Andy, I have started exploring nonmemtomrgsolve. I get the correct output in the console, but for some reason I do not get the R file. I only get an empty R file. I have so far tried the 1 compartment model from the example that you have provided. What can I do in this regard? thanks in advance Ali

Originally posted by @SepassianAcademy in #33 (comment)

@Andy00000000000
Copy link
Owner Author

Hi Ali,

Are you getting any warning or error messages? Can you try writing a test file using the below code and let me know whether that works?

`
tmp_dir <- "/home/epd/Documents/" # change this line to your file path for writing the R file

tmp_pth <- paste0(tmp_dir,"Test.R")
tmp_file <- file(tmp_pth)
cat("'",file=tmp_pth)
cat("Hello World",file=tmp_pth,sep="\n\n",append=T)
cat("This is Working",file=tmp_pth,append=T)
cat("'",file=tmp_pth,append=T)
close(tmp_file)
`

@Andy00000000000
Copy link
Owner Author

Andy00000000000 commented Nov 14, 2024

SepassionAcademy post (in discussions, copied here to issues):

Hi Andy I did try to use the code but it does not work, I have a modified version that works fine for me. I made some local modifications to the writemrgsolve function, which works fine now. However I am not able to incorporate this in to the main nonmemtomrgsolve function

FUNCTION WRITE MRGSOLVE

#' Write the mrgsolve code to an R file
#'
#' Writes the mrgsolve code, translated from the input NONMEM run, to an R file.
#'
#' @param mrg_code Dataframe of the NONMEM model translated into mrgsolve code
#' @param filename String of the name for the mrgsolve output file without the .R extension
#' @param dir String of the directory path to the NONMEM run files
#'
#' @return R file of the mrgsolve code
#'
#' https://github.com/examples
#' # writemrgsolve()
#'
#' @export

writemrgsolve <- function(mrg_code = NULL, filename = "mrgsolve_code0", dir = NULL){

tdir <- ifelse(is.na(dir) | is.null(dir), "", paste0(dir,"/"))
nme_pth <- paste0(tdir,filename,".R")

Prepare the content to be written to the file

file_content <- c("code <- '", mrg_code$V1, "'")

Write the contents to the file

writeLines(file_content, nme_pth)

print("Mrgsolve Code was Saved to an R File")
}

@Andy00000000000
Copy link
Owner Author

SepassionAcademy post (in discussions, copied here to issues):

These are the errors that I get currently:
In close.connection(file) :
Problem closing connection: Operation not permitted
Error in file(con, "w") : cannot open the connection
In addition: Warning message:
In file(con, "w") :
cannot open file '/mrgsolve-code-V0_mod1.R': Permission denied

I have checked the permission to creating files in my cloud and there are no issues there.

@Andy00000000000
Copy link
Owner Author

@SepassionAcademy

Sorry for the delay getting back to you, I was traveling for ACoP. It does look like there is a read/write permission issue based on those error messages. For your workaround, did the R file that writeLines() wrote to already exist? Or was it created by your modified writemrgsolve function?

From the above code you sent, it looked like the R file already existed...? Which makes me suspect that you have access to create/edit files, but that when you are running R it is not being ran as administrator which then creates the "Permission denied" when trying to create the R file to write the output to. If it's possible, could you delete any files that nonmem2mrgsolve would write to (or change the output file name), then try to run R as administrator (if possible), and then re-test the default/original nonmem2mrgsolve?

In the meantime, I'll think about what else we could do to get this working for you.

Thanks,
Andy

@SepassianAcademy
Copy link

Hi again, thank you for your response. I have managed to fix the previously mentioned issues and I can run the examples that you have provided correctly. It seems to me that the translation is fine for 1 and 2 compartment models. The accuracy is not super high as you also have mentioned in the code. Moreover, the differential equations must be written explicitly. As you know many NONMEM users use functions such as ADVAN1 etc instead of writing the equations explicitly. Is it possible to take this in to account in translation without writing the equations explicitly. Maybe we could meet on google meets to talk about improvements. I am tasked in Novo Nordisk to implement this package in our day to day work and we are really interested. Thank you in advance

@SepassianAcademy
Copy link

Another issue is that some of the comments in the code get deleted, when model translation is happening. I think from a practical and pedagogical point of view it would be nice to have the comments in the translated code.

@Andy00000000000
Copy link
Owner Author

Glad to hear the permission issue was resolved. I do have an enhancement issue open for building in the other advans (issue #28) and hope to get to that. I will open a new issue regarding your suggestion about retaining comments and will then close this one.

I would be happy to discuss over a google meet. Please reach out over email ([email protected]) and we can set up a time.

Thanks, Andy

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