Tinderbox & R (RStudio)

Per [this]*Pandoc Working Group - #15 by mwra) let’s kick off a new thread on discussing the relationship between Tinderbox and R. I’ve always wanted to learn R.

Using the Termina and Homebrew, I installed R and RStudio (you need both). I think I played running a regression in RE by asking ChatGPT who to run a regression in R. I also asked it how to run a regression. I found that I needed to (got to) install libraries for plotly and ggpplot. Again, chat gave me the instructions for doing this, e.g. ‘install.packages(“plotly”)’. I can see how I can use action code to transform my data into the inputs that R needs to run any visualization. Pretty darn cool! Here is a question, is there a command line that can be sent from TBX to R and then have the result from R return back to TBX? Could it return plat images as well, not just text? For instance, could R send a plat image to the hard drive and return the image path to Tinderbox?

@mwra, might this be a better (different) way than mucking around with the template we were playing with yesterday? I see pros and cons.

Again, I’m just 15 minutes into playing with R, so I have tons of newbie questions. I’ll try to answer them myself in time, but I’ll throw them out here for now.

1 Like

Ok, in my testing I’m nearly there.

  1. Successfully exporting task list for gannt charge to hardrive
  2. trigger command to have R run it and save plat to file on harddrive

It the next step is failing me. I’m trying to run an osascript osascript -e 'tell application "Tinderbox 10" to set value of attribute "MediaFileName" of note "FigTest" to "tinderboxplot.png"' and I’m getting this error `"Tinderbox 10 got an error: Can’t set note “FigTest”'. Can TBX respond to an osascript call? Is there something in my script that is wrong? I’m bumbling around in the dark. Any guidance would be most appreciated.

1 Like

I have used R extensively for nearly 20 years. Definitely what you want to do is doable. RStudio is not strictly necessary to use R, it’s just a nice IDE. Posit has a new one that’s a bit more polyglot built off VSCodium called Positron. But you can write and run R code in whatever text editor you want (vim/emacs/VS Code/etc). RStudio is probably the best at the moment for those who primarily use R and who make use of some of the more advanced R features for compiling literate programming documents. The new big thing in this space (which I know you will be into, @satikusala) is called quarto. It’s a command line program for rendering qmd (quarto markdown, the sucessor to rmarkdown) documents to various outputs via pandoc.

The other thing to know is that most people these days in R use a set of packages called the tidyverse to work with data (e.g. the dplyr, readr, tidyr packages) and make plots (ggplot2). This is in contrast to ‘base’ R, which is out of the box R (while it’s very flexible, the syntax is more clunky and graphic defaults not as visually appealing, for example).

2 Likes

I am happy to be a resource to you/others on your R journey.

3 Likes

Great book to start with: O’Reilly’s R for Data Science:
https://r4ds.hadley.nz

Software Carpentry (global nonprofit helping teach scientists proper coding practices) has a good intro lesson for the basics:
https://swcarpentry.github.io/r-novice-gapminder/

@naupaka Thanks!!! Great stuff. It would be cool if you could join us for a meetup one of these days.

@eastgate got me on the books for the Jan 25 meetup :smile: although I didn’t quite yet have a plan about what I was going to share/present.

Would be very excited to talk all things R/literate programming/pandoc/quarto and have a discussion about ways to integrate those with Tinderbox.

2 Likes

Michael, have a look at https://quarto.org/
I am sure it will resonate with you!

I look forward to exploring links between Tinderbox and R / RStudio / Quarto,

2 Likes

I agree! - I found Wickham’s book very helpful.

But @satikusala, are you already familiar with Python? If you are, and just starting off with a big personal push into stats, you might want to pause and weigh pros and cons of R vs. Python for stats before you fully commit? There’s another free resource in the same O’Rielly series for this "Python for Data Analysis’ Python for Data Analysis, 3E

Generally the whole O’Rielly stats series is very useful

There’s also a free online side by side method/learning resource/comparison book for the two An Introduction to R and Python For Data Analysis: A Side By Side Approach | Taylor R. Brown

Personally I’d already gone down the R route, and Python remains on my ‘I really wish I had more time’ list! I’d be interested in any interlinkage with Tinderbox that comes up.

1 Like

Is there any way we can switch you to Jan. 26. We are going to change the alternating days for the meetups, starting in January, because I have a conflict on the second Saturday of every month.

I am not, but would love to learn.

Perhaps kill two birds with one stone? (to use a thoroughly ecologically unsound metaphor). I don’t know the answer, it just I’ve pondered exactly this dilemma!

1 Like

I’m a beginner in R, but I use quarto. I’m working on enabling Tinderbox to export for quarto book format ( qmd and yml files). Additionally, I’m implementing input assistance for cross-references using ziplinks and mermaid flowcharts.

My demo tbx file and output example are available on github.

3 Likes

Sure, Jan 26th works just as well for me.

1 Like

This looks very cool!

3 Likes

Cool. I tried downloading the demo file, but it did not work for me. Can you provide a direct link to download it?

Of course.
Demo_TBX_for_Quarto.tbx (13.1 MB)

Note: The _quarto_manuscript does not work.

This is extremely cool!!! Would you be willing to join a meetup one of these days and walk us through this? Are you in Japan? If so, to make it easier for you, maybe you could join our first Friday of the month APAN meeetup with is 4:00 PM PST/9:00 AM JST. Next one is January 3.

Thank you for inviting me to the meetup. As you may have guessed, I live in Japan. But, I’m very sorry, I can’t speak English. so it’s difficult for me to communicate in real-time.
It will take me some time, but I’d like to create a video explaining how to use it instead.

4 Likes

This popped up in my digest email, and caught my attention.

I’m a proficient long-term R user, and use both RMarkdown and quarto (but never Rstudio, unless I’m teaching), and python as well (mix-and match R and python in a quarto document is great). I’ve never pondered interfacing with with Tinderbox, largely because I’ve never had a use case where it would help. Certainly some of the ideas batted around here about creating images to include in a Tbx document could have nifty applications, though.

I could also see using Tinderbox as a very fancy organizational tool for quarto/Rmarkdown, with a little work to configure the markdown export template for code chunks. Both are dialects of markdown, so that could be feasible.

Hm.

2 Likes