Ancestors

Written by Michael Chirico on 2024-08-23 at 03:52

I must be re-inventing the wheel here -- what package/function should I be using instead? #rstats

The idea is -- for environments where we don't have an IDE / ctrl+Enter-friendly execution environment, source() a script but expression-by-expression (a la browser()/debug()).

So I can do .DebuggedScript(r_script)() and then start 'n' my way through it.

=> View attached media

=> More informations about this toot | More toots from michaelchirico@fosstodon.org

Written by Heather Turner :rstats: on 2024-08-23 at 09:25

@michaelchirico You can simplify this a bit with

library(readr)
x <- parse(text = paste("browser()", "{", read_file("script.R"), "}", sep = "\n"))
eval(x)

For base R only, you could replace the read_file call with

paste(readLines("script.R"), collapse = "\n")

Maybe you could write a helper function to add the initial browser();{ at a line of your choice to avoid debugging the whole script.

=> More informations about this toot | More toots from HeathrTurnr@fosstodon.org

Toot

Written by Michael Chirico on 2024-08-23 at 16:05

@HeathrTurnr IMO readChar() should be the better choice here, it's just clunky for now...

https://stat.ethz.ch/pipermail/r-devel/2024-January/083148.html

=> More informations about this toot | More toots from michaelchirico@fosstodon.org

Descendants

Written by Heather Turner :rstats: on 2024-08-23 at 17:24

@michaelchirico Interesting this came up recently - it does seem like there should be a neater way to do this. But Duncan Murdoch has a point about Windows-style newlines and I think it matters here, e.g.

x <- parse(text = paste("browser()", "{", "x <- 1:3\ny <- rnorm(x)", "}", sep = "\n"))

works, but

x <- parse(text = paste("browser()", "{", "x <- 1:3\r\ny <- rnorm(x)", "}", sep = "\n"))

throws an error.

=> More informations about this toot | More toots from HeathrTurnr@fosstodon.org

Written by Michael Chirico on 2024-08-23 at 18:15

@HeathrTurnr I think it's a useful thing to keep in mind, the behavior you found here is strange. parse() on windows files works fine... anyway, for your approach, I'd do:

parse(text = c(

'browser()',

'{',

readLines(f),

'}'

))

and let parse() handle the concatenation part as needed.

=> More informations about this toot | More toots from michaelchirico@fosstodon.org

Written by Heather Turner :rstats: on 2024-08-24 at 06:50

@michaelchirico Ah yes that’s even simpler!

=> More informations about this toot | More toots from HeathrTurnr@fosstodon.org

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113012189040248298
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
268.781086 milliseconds
Gemini-to-HTML Time
1.092212 milliseconds

This content has been proxied by September (3851b).