I am not sure about QuPath scripting, but it is certainly possible to do using an R script run after the QuPath script.
See:
https://github.com/qupath/qupath/issues/79Better yet, you can run both the R script and the QuPath script from the command line, if you want to automate the whole thing. Or you could have a QuPath script that calls the R script on your data folder, and run it after the QuPath cell detection script is done. There are several other posts here about running QuPath from the command line without opening it, and I have a few examples of calling python scripts from the command line within QuPath that could be modified to work on an R script.