Runnable R packages

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Runnable R packages

David Lindelof-3
Dear all,

I’m working as a data scientist in a major tech company. I have been using
R for almost 20 years now and there’s one issue that’s been bugging me of
late. I apologize in advance if this has been discussed before.

R has traditionally been used for running short scripts or data analysis
notebooks, but there’s recently been a growing interest in developing full
applications in the language. Three examples come to mind:

1) The Shiny web application framework, which facilitates the developent of
rich, interactive web applications
2) The httr package, which provides lower-level facilities than Shiny for
writing web services
3) Batch jobs run by data scientists according to, say, a cron schedule

Compared with other languages, R’s support for such applications is rather
poor. The Rscript program is generally used to run an R script or an
arbitrary R expression, but I feel it suffers from a few problems:

1) It encourages developers of batch jobs to provide their code in a single
R file (bad for code structure and unit-testability)
2) It provides no way to deal with dependencies on other packages
3) It provides no way to "run" an application provided as an R package

For example, let’s say I want to run a Shiny application that I provide as
an R package (to keep the code modular, to benefit from unit tests, and to
declare dependencies properly). I would then need to a) uncompress my R
package, b) somehow, ensure my dependencies are installed, and c) call
runApp(). This can get tedious, fast.

Other languages let the developer package their code in "runnable"
artefacts, and let the developer specify the main entry point. The
mechanics depend on the language but are remarkably similar, and suggest a
way to implement this in R. Through declarations in some file, the
developer can often specify dependencies and declare where the program’s
"main" function resides. Consider Java:

Artefact: .jar file
Declarations file: Manifest file
Entry point: declared as 'Main-Class'
Executed as: java -jar <jarfile>

Or Python:

Artefact: Python package, typically as .tar.gz source distribution file
Declarations file: setup.py (which specifies dependencies)
Entry point: special __main__() function
Executed as: python -m <package>

R has already much of this machinery:

Artefact: R package
Declarations file: DESCRIPTION
Entry point: ?
Executed as: ?

I feel that R could benefit from letting the developer specify, possibly in
DESCRIPTION, how to "run" the package. The package could then be run
through, for example, a new R CMD command, for example:

R CMD RUN <package> <args>

I’m sure there are plenty of wrinkles in this idea that need to be ironed
out, but is this something that has ever been considered, or that is on R’s
roadmap?

Thanks for reading so far,



David Lindelöf, Ph.D.
+41 (0)79 415 66 41 or skype:david.lindelof
http://computersandbuildings.com
Follow me on Twitter:
http://twitter.com/dlindelof

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Runnable R packages

Gergely Daróczi
Dear David, sharing some related (subjective) thoughts below.

On Mon, Jan 7, 2019 at 9:53 PM David Lindelof <[hidden email]> wrote:

>
> Dear all,
>
> I’m working as a data scientist in a major tech company. I have been using
> R for almost 20 years now and there’s one issue that’s been bugging me of
> late. I apologize in advance if this has been discussed before.
>
> R has traditionally been used for running short scripts or data analysis
> notebooks, but there’s recently been a growing interest in developing full
> applications in the language. Three examples come to mind:
>
> 1) The Shiny web application framework, which facilitates the developent of
> rich, interactive web applications
> 2) The httr package, which provides lower-level facilities than Shiny for
> writing web services
> 3) Batch jobs run by data scientists according to, say, a cron schedule
>
> Compared with other languages, R’s support for such applications is rather
> poor. The Rscript program is generally used to run an R script or an
> arbitrary R expression, but I feel it suffers from a few problems:
>
> 1) It encourages developers of batch jobs to provide their code in a single
> R file (bad for code structure and unit-testability)

I think it rather encourages developers to create (internal) R
packages and use those from the batch jobs. This way the structure is
pretty clean, sharing code between scripts is easy, unit testing can
be done within the package etc.

> 2) It provides no way to deal with dependencies on other packages

See above: create R package(s) and use those from the scripts.

> 3) It provides no way to "run" an application provided as an R package
>
> For example, let’s say I want to run a Shiny application that I provide as
> an R package (to keep the code modular, to benefit from unit tests, and to
> declare dependencies properly). I would then need to a) uncompress my R
> package, b) somehow, ensure my dependencies are installed, and c) call
> runApp(). This can get tedious, fast.

You can provide your app as a Docker image, so that the end-user
simply calls a "docker pull" and then "docker run" -- that can be done
from a user-friendly script as well.
Of course, this requires Docker to be installed, but if that's a
problem, probably better to "ship" the app as a web application and
share a URL with the user, eg backed by shinyproxy.io

>
> Other languages let the developer package their code in "runnable"
> artefacts, and let the developer specify the main entry point. The
> mechanics depend on the language but are remarkably similar, and suggest a
> way to implement this in R. Through declarations in some file, the
> developer can often specify dependencies and declare where the program’s
> "main" function resides. Consider Java:
>
> Artefact: .jar file
> Declarations file: Manifest file
> Entry point: declared as 'Main-Class'
> Executed as: java -jar <jarfile>
>
> Or Python:
>
> Artefact: Python package, typically as .tar.gz source distribution file
> Declarations file: setup.py (which specifies dependencies)
> Entry point: special __main__() function
> Executed as: python -m <package>
>
> R has already much of this machinery:
>
> Artefact: R package
> Declarations file: DESCRIPTION
> Entry point: ?
> Executed as: ?
>
> I feel that R could benefit from letting the developer specify, possibly in
> DESCRIPTION, how to "run" the package. The package could then be run
> through, for example, a new R CMD command, for example:
>
> R CMD RUN <package> <args>
>
> I’m sure there are plenty of wrinkles in this idea that need to be ironed
> out, but is this something that has ever been considered, or that is on R’s
> roadmap?
>
> Thanks for reading so far,
>
>
>
> David Lindelöf, Ph.D.
> +41 (0)79 415 66 41 or skype:david.lindelof
> http://computersandbuildings.com
> Follow me on Twitter:
> http://twitter.com/dlindelof
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Runnable R packages

Dirk Eddelbuettel
In reply to this post by David Lindelof-3

On 3 January 2019 at 11:43, David Lindelof wrote:
| Dear all,
|
| I’m working as a data scientist in a major tech company. I have been using
| R for almost 20 years now and there’s one issue that’s been bugging me of
| late. I apologize in advance if this has been discussed before.
|
| R has traditionally been used for running short scripts or data analysis
| notebooks, but there’s recently been a growing interest in developing full
| applications in the language. Three examples come to mind:
|
| 1) The Shiny web application framework, which facilitates the developent of
| rich, interactive web applications
| 2) The httr package, which provides lower-level facilities than Shiny for
| writing web services
| 3) Batch jobs run by data scientists according to, say, a cron schedule

That is a bit of a weird classification of "full applications". I have done
this about as long as you but I also provided (at least as tests and demos)
  i)  GUI apps using tcl/tk (which comes with R) and
  ii) GUI apps with Qt (or even Wt), see my RInside package.

But my main weapon for 3) is littler. See

   https://cran.r-project.org/package=littler

and particularly the many examples at

   https://github.com/eddelbuettel/littler/tree/master/inst/examples
 
| Compared with other languages, R’s support for such applications is rather
| poor. The Rscript program is generally used to run an R script or an
| arbitrary R expression, but I feel it suffers from a few problems:
|
| 1) It encourages developers of batch jobs to provide their code in a single
| R file (bad for code structure and unit-testability)
| 2) It provides no way to deal with dependencies on other packages
| 3) It provides no way to "run" an application provided as an R package

Err, no. See the examples/ directory above. About every single one uses
packages.

As illustrations I have long-running and somewhat visible cronjobs that are
implemented the same way: CRANberries (since 2007, now running hourly) and
CRAN Policy Watch (running once a day). Because both are 'hacks' I never
published the code but there is not that much to it. CRANberries just queries
CRAN, compares to what it had last, and writes out variants of the
DESCRIPTION file to text where a static blog engine (like Hugo, but older)
makes a feed and html pagaes out of it.  Oh, and we tweet because "why not?".
 
| For example, let’s say I want to run a Shiny application that I provide as
| an R package (to keep the code modular, to benefit from unit tests, and to
| declare dependencies properly). I would then need to a) uncompress my R
| package, b) somehow, ensure my dependencies are installed, and c) call
| runApp(). This can get tedious, fast.

Disagree here too. At work, I just write my code, organize it in packages,
update the packages and have shiny expose whatever makes sense.

| Other languages let the developer package their code in "runnable"
| artefacts, and let the developer specify the main entry point. The
| mechanics depend on the language but are remarkably similar, and suggest a
| way to implement this in R. Through declarations in some file, the
| developer can often specify dependencies and declare where the program’s
| "main" function resides. Consider Java:
|
| Artefact: .jar file
| Declarations file: Manifest file
| Entry point: declared as 'Main-Class'
| Executed as: java -jar <jarfile>
|
| Or Python:
|
| Artefact: Python package, typically as .tar.gz source distribution file
| Declarations file: setup.py (which specifies dependencies)
| Entry point: special __main__() function
| Executed as: python -m <package>
|
| R has already much of this machinery:
|
| Artefact: R package
| Declarations file: DESCRIPTION
| Entry point: ?
| Executed as: ?
|
| I feel that R could benefit from letting the developer specify, possibly in
| DESCRIPTION, how to "run" the package. The package could then be run
| through, for example, a new R CMD command, for example:
|
| R CMD RUN <package> <args>
|
| I’m sure there are plenty of wrinkles in this idea that need to be ironed
| out, but is this something that has ever been considered, or that is on R’s
| roadmap?

Hm. If _you_ have an itch to scratch here why don't _you_ implement a draft.

Dirk

--
http://dirk.eddelbuettel.com | @eddelbuettel | [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Runnable R packages

Murray Stokely
In reply to this post by David Lindelof-3
Some other major tech companies have in the past widely use Runnable R
Archives (".Rar" files), similar to Python .par files [1], and integrate
them completely into the proprietary R package build system in use there.
I thought there were a few systems like this that had made their way to
CRAN or the UseR conferences, but I don't have a link.

Building something specific to your organization on top of the python .par
framework to archive up R, your needed packages/shared libraries, and other
dependencies with a runner script to R CMD RUN your entry point in a
sandbox is pretty straightforward way to have control in a way that makes
sense for your environment.

      - Murray

[1] https://google.github.io/subpar/subpar.html

On Mon, Jan 7, 2019 at 12:53 PM David Lindelof <[hidden email]> wrote:

> Dear all,
>
> I’m working as a data scientist in a major tech company. I have been using
> R for almost 20 years now and there’s one issue that’s been bugging me of
> late. I apologize in advance if this has been discussed before.
>
> R has traditionally been used for running short scripts or data analysis
> notebooks, but there’s recently been a growing interest in developing full
> applications in the language. Three examples come to mind:
>
> 1) The Shiny web application framework, which facilitates the developent of
> rich, interactive web applications
> 2) The httr package, which provides lower-level facilities than Shiny for
> writing web services
> 3) Batch jobs run by data scientists according to, say, a cron schedule
>
> Compared with other languages, R’s support for such applications is rather
> poor. The Rscript program is generally used to run an R script or an
> arbitrary R expression, but I feel it suffers from a few problems:
>
> 1) It encourages developers of batch jobs to provide their code in a single
> R file (bad for code structure and unit-testability)
> 2) It provides no way to deal with dependencies on other packages
> 3) It provides no way to "run" an application provided as an R package
>
> For example, let’s say I want to run a Shiny application that I provide as
> an R package (to keep the code modular, to benefit from unit tests, and to
> declare dependencies properly). I would then need to a) uncompress my R
> package, b) somehow, ensure my dependencies are installed, and c) call
> runApp(). This can get tedious, fast.
>
> Other languages let the developer package their code in "runnable"
> artefacts, and let the developer specify the main entry point. The
> mechanics depend on the language but are remarkably similar, and suggest a
> way to implement this in R. Through declarations in some file, the
> developer can often specify dependencies and declare where the program’s
> "main" function resides. Consider Java:
>
> Artefact: .jar file
> Declarations file: Manifest file
> Entry point: declared as 'Main-Class'
> Executed as: java -jar <jarfile>
>
> Or Python:
>
> Artefact: Python package, typically as .tar.gz source distribution file
> Declarations file: setup.py (which specifies dependencies)
> Entry point: special __main__() function
> Executed as: python -m <package>
>
> R has already much of this machinery:
>
> Artefact: R package
> Declarations file: DESCRIPTION
> Entry point: ?
> Executed as: ?
>
> I feel that R could benefit from letting the developer specify, possibly in
> DESCRIPTION, how to "run" the package. The package could then be run
> through, for example, a new R CMD command, for example:
>
> R CMD RUN <package> <args>
>
> I’m sure there are plenty of wrinkles in this idea that need to be ironed
> out, but is this something that has ever been considered, or that is on R’s
> roadmap?
>
> Thanks for reading so far,
>
>
>
> David Lindelöf, Ph.D.
> +41 (0)79 415 66 41 or skype:david.lindelof
> http://computersandbuildings.com
> Follow me on Twitter:
> http://twitter.com/dlindelof
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Runnable R packages

Dirk Eddelbuettel
In reply to this post by Gergely Daróczi

On 7 January 2019 at 22:09, Gergely Daróczi wrote:
| You can provide your app as a Docker image, so that the end-user
| simply calls a "docker pull" and then "docker run" -- that can be done
| from a user-friendly script as well.
| Of course, this requires Docker to be installed, but if that's a
| problem, probably better to "ship" the app as a web application and
| share a URL with the user, eg backed by shinyproxy.io

Excellent suggestion.

Dirk

--
http://dirk.eddelbuettel.com | @eddelbuettel | [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Runnable R packages

Iñaki Ucar
In reply to this post by Gergely Daróczi
On Mon, 7 Jan 2019 at 22:09, Gergely Daróczi <[hidden email]> wrote:
>
> Dear David, sharing some related (subjective) thoughts below.
>
> You can provide your app as a Docker image, so that the end-user
> simply calls a "docker pull" and then "docker run" -- that can be done
> from a user-friendly script as well.
> Of course, this requires Docker to be installed, but if that's a
> problem, probably better to "ship" the app as a web application and
> share a URL with the user, eg backed by shinyproxy.io

If Docker is a problem, you can also try podman: same usage,
compatible with Dockerfiles and daemon-less, no admin rights required.

https://podman.io/

Iñaki

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel