[R-pkg-devel] Simple way to run code during package install
I have some code in rgl and rgl2gltf that should be run during the package install process, and not later. (It's a call to rgl::makeDependency, which does some stuff with Javascript files and writes into the package installation directory, saving the paths of the files it wrote.) Currently rgl handles this by simply placing calls to makeDependency in one of the .R files, relying on the fact that they are run at install time and not later. It creates rgl:::rglDependency and another similar object. That works fine. Tomas just pointed out to me that rgl2gltf is trying to modify its installation location after installation. This is happening because it calls makeDependency in a function the user can call, and that's bad, so I'm fixing it. The problem is that rgl2gltf uses Roxygen for documentation, and Roxygen executes all the code in the package when it is producing Rd files. (Normally this just creates the functions in the package, it doesn't actually call them, so it's harmless. But calling makeDependency from Roxygen fails because I wasn't expecting that.) So I'd like to ask for suggestions for the simplest way to deal with this in rgl2gltf. 1. One choice is to fix rgl::makeDependency so it can tell that it is being run after installation, and stop trying to write any files. It should just return the object. I can probably do this, but I've just had two rgl releases in the last few weeks, so I'd prefer to limit the changes to rgl2gltf. 2. I can use pkgload::is_loading() to detect the load_all() call from Roxygen and not run makeDependency in that situation. But that forces a dependence on pkgload, and that's not very appealing. 3. Maybe I can mark the file that contains the makeDependency call so that Roxygen ignores it. Is that possible? 4. I can write a Makevars file that runs makeDependency. That seems like a pretty heavyweight solution, especially since I need to save the result of the call so it is available later. Does anyone else have this problem, and a nice solution for it? Duncan Murdoch __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
[R-pkg-devel] Closing a display window from a program
In answer to my own posting about this, I found the following partially answers what I need. The task is to display a file (in my case a pdf, for which 'xdisp' contains the string for the command to do this. See below for the reason this is a variable. The displayed file has information I will need to possibly enter into other program structures and which may be in the form of pixels rather than text or numbers. Later, I wish to close the display when the need is past. Clearly, that step could be left to the user, but I believe in decluttering the screen as much as I can. cmd<-cmd <- paste0(xdisp," ",xdocfn," &") # add & to keep running and return?? system(cmd) pidcmd<-paste0("pgrep -f '",cmd,"'") spid<-system(pidcmd, intern=TRUE) # gets spid, but stays running # For some reason increased by 1 spid<-as.integer(spid)-1 Later on I can close the display with # Kill the display of the statement now. tmp<-readline("Kill the bill display process now") kcmd<-paste0("kill -9 ",spid) Clearly I'm on a Linux system (Mint 22 Wilma) I've not considered how I'd do this in Windows, but would welcome suggestions as I believe cross-platform solutions widen the utility of any software. I also looked at the CRAN package ps, and found there are ways to use some of its tools. They may, in fact, be more system-neutral, so are still on my radar for consideration. My posting asked also if the display could be controlled as to position and size. I have not yet found how to do that, but have found choice of the pdf display program a partial help. I am currently setting xdisp to xpdf in an "ini" file, for which the CRAN package ini is most helpful. For information, I put below a solution to an Rstudio matter that arose. Comments and discussion welcome. Best, John Nash PS. In building this code in Rstudio and using browseURL(file) to open the display, I got a warning error about "signal 10". This can be overcome by using browseURL(file, browser="xdg-open"). However, "file" must be either a simple filename of a file in the current directory, or a fully qualified path. Use of the shortcut "~/" for the home directory fails. This issue does not arise for R in a terminal. __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Closing a display window from a program
Le 19/11/2024 à 14:41, J C Nash a écrit : In answer to my own posting about this, I found the following partially answers what I need. The task is to display a file (in my case a pdf, for which 'xdisp' contains the string for the command to do this. See below for the reason this is a variable. The displayed file has information I will need to possibly enter into other program structures and which may be in the form of pixels rather than text or numbers. Later, I wish to close the display when the need is past. Clearly, that step could be left to the user, but I believe in decluttering the screen as much as I can. cmd<-cmd <- paste0(xdisp," ",xdocfn," &") # add & to keep running and return?? system(cmd) pidcmd<-paste0("pgrep -f '",cmd,"'") spid<-system(pidcmd, intern=TRUE) # gets spid, but stays running # For some reason increased by 1 spid<-as.integer(spid)-1 Later on I can close the display with # Kill the display of the statement now. tmp<-readline("Kill the bill display process now") kcmd<-paste0("kill -9 ",spid) Clearly I'm on a Linux system (Mint 22 Wilma) I've not considered how I'd do this in Windows, but would welcome suggestions as I believe cross-platform solutions widen the utility of any software. I also looked at the CRAN package ps, and found there are ways to use some of its tools. They may, in fact, be more system-neutral, so are still on my radar for consideration. My posting asked also if the display could be controlled as to position and size. I have not yet found how to do that, but have found choice of the pdf display program a partial help. I am currently setting xdisp to xpdf in an "ini" file, for which the CRAN package ini is most helpful. For information, I put below a solution to an Rstudio matter that arose. Comments and discussion welcome. Best, John Nash PS. In building this code in Rstudio and using browseURL(file) to open the display, I got a warning error about "signal 10". This can be overcome by using browseURL(file, browser="xdg-open"). However, "file" must be either a simple filename of a file in the current directory, or a fully qualified path. Use of the shortcut "~/" for the home directory fails. may be path.exapnd()? > path.expand("~/tmp/my.pdf") [1] "/home/sokol/tmp/my.pdf" This issue does not arise for R in a terminal. __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel