Re: [R-pkg-devel] vignette with "Run Examples"

2023-12-12 Thread Duncan Murdoch

On 12/12/2023 2:24 a.m., Sigbert Klinke wrote:

Hi,

is it possible to get a button or link to run an example in a vignette
like we see for the examples in the R help?



Others have explained why this is hard.  An alternative might be to run 
the examples when you produce your vignette, but hide the results until 
a button is pressed to display them.


Duncan Murdoch

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] vignette with "Run Examples"

2023-12-12 Thread Ivan Krylov
On Tue, 12 Dec 2023 08:24:11 +0100
Sigbert Klinke  wrote:

> is it possible to get a button or link to run an example in a vignette

Technically, yes, but very hard to implement in practice.

Vignettes are a form of literate programming, expressed in terms of
files: there's a source file containing code mixed with prose, and
there are two programs, one of which extracts the code into a runnable
.R file and the other renders the code together with prose and any
resulting plots into a human-readable document. A link to run examples
implies that there's R running somewhere, which cannot be guaranteed by
the time the human-readable document is opened by the human.

One way around this problem would be to embed a copy of webR [*] in the
document so that R would run in the browser. This involves a
significant developer effort and would either bloat your vignette to
the size of an R installation or make it depend on external resources
to load webR from (that could go away or spy on the user). webR is
still experimental; last time I tried it, it crashed the browser tab
when I invoked functions from the quadprog package.

Another way would be to add a hack to the vignette engine to start a
server at vignette rendering time, insert the link to this server into
the vignette as it's being rendered and hope that the server is still
running by the time the vignette is opened. This would require the user
to re-render the vignette every time they restart the server.

Technically, one could also invent a completely new kind of vignette
engine that would output self-contained executable files with a
document rendering engine and R built in, so that a click on the "Run
examples" would use that built-in R. This is basically the webR
solution without the web and with a lot of extra pain.

You could also fake some of it by writing extra JavaScript (with the
help of third-party statistics libraries, e.g. [**]) to do the same
thing in the browser as is done in R, but that's still a lot of work
for little benefit.

Yet another way would be to make these links point to an external
service somewhere on the Internet that would run the R code. Since R is
not designed to work with untrusted input (not to mention untrusted
users entering code), that would be an informational security nightmare
both on your side (R would have to run in locked-down read-only
disposable virtual machines hardened against sandbox escape and
privilege escalation exploits) and on the GDPR side of things.

There are doubtlessly more approaches, but I think they would all be
this convoluted or worse.

-- 
Best regards,
Ivan

[*] https://docs.r-wasm.org/webr/latest/

[**] https://github.com/svkucheryavski/mdatools-js

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] vignette with "Run Examples"

2023-12-11 Thread Deepayan Sarkar
On Tue, 12 Dec 2023 at 12:54, Sigbert Klinke 
wrote:

> Hi,
>
> is it possible to get a button or link to run an example in a vignette
> like we see for the examples in the R help?
>

Just to understand your expectations: The 'run examples' option only works
within the "dynamic" R help system, because it has access to a running
version of R. Vignettes can also be viewed through the dynamic system, but
they perhaps more useful as standalone documentation (say on the CRAN page
of a package). Would it be really useful to be able to run the code only in
the limited setup of dynamic help?

The other issue is that examples are expected to be short and simple,
whereas vignettes can often be more complicated. They will also typically
include the "output" from running the code, so what would be the point of
running it again?

If you want to really try the vignette code, then the package documentation
page typically includes the R code extracted from a vignette, which you can
download and run. And of course with IDEs like ESS or RStudio, you can
simply open the vignette source and run the code interactively.

Best,
-Deepayan


>
> Thanks Sigbert
>
> --
> https://hu.berlin/sk
> https://www.stat.de/faqs
> https://hu.berlin/mmstat
> https://hu.berlin/mmstat-ar
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


[R-pkg-devel] vignette with "Run Examples"

2023-12-11 Thread Sigbert Klinke

Hi,

is it possible to get a button or link to run an example in a vignette 
like we see for the examples in the R help?


Thanks Sigbert

--
https://hu.berlin/sk
https://www.stat.de/faqs
https://hu.berlin/mmstat
https://hu.berlin/mmstat-ar

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel