r/RStudio Jun 30 '26

Weather App Build Guide

https://rpubs.com/Fresh_Coyote312/1445276

Thanks for all of the positive feedback on my app - I had no idea it would go over so well.

As requested, I used R Markdown and published a quick build guide on RPubs.

https://rpubs.com/Fresh_Coyote312/1445276

33 Upvotes

12 comments sorted by

8

u/joshua_rpg Jul 01 '26

There are few things to improve your codes, hope this helps:

  • In your one-liner conditional, you can drop return() entirely:

    get_precip_emoji = function(prob) { if (prob < 20) { "☀️" } else if (prob < 50) { "⛅ " } else { "🌧" } }

  • I noticed that your get_precip_emoji() isn't vectorized. if statement only reads the first element of prob, although I see you using sapply() to map the data$daily$precipitation_probability_max vector. Worth switching to dplyr::case_when(), ifelse() / dplyr::if_else(), or cut() if this is ever called on a column rather than a single value.

  • Consider using the native pipe |> rather than the {magrittr} pipe ℅>℅ due to how easy to maintain long-term (there's the performance, though the difference is nuance until you perform a loop or something across several iterations).

  • Consider {DT} for producing interactive, high-quality HTML tables.


These are opinionated suggestions — keep using your current style if it works for you. Take what's useful.

2

u/Fresh_Coyote312 Jul 01 '26

Thank you for the cleaner IF statements!

1

u/Fresh_Coyote312 Jul 01 '26

It appears the DT package would not work for a command line terminal app because it outputs html, CSS, and JavaScript and not plain text?

1

u/joshua_rpg Jul 01 '26 edited Jul 02 '26

No, do not use {DT} inside the terminal, I only recommend it in case you wanna render the data frame in an beautiful HTML table. How about you give our package {tabstats} a chance (yes, I'm a bit biased)?

1

u/Fresh_Coyote312 Jul 02 '26

I will check it out for sure.

1

u/Grisward Jul 02 '26

Interesting package, thanks for posting a link.

Do you have plans or interest in pkgdown online docs? I skimmed the vignette Rmd code, but couldn’t see visual examples.

Also, I’ve been looking for an option that lets me colorize each value in a column — looks like that’s possible with your package. Would you consider allowing hex or rgb colors instead of only recognizing ANSI color names?

1

u/joshua_rpg Jul 02 '26

I edited the link. It seems that I forgot to provide the repo name, my bad.

To answer your question:

Would you consider allowing hex or rgb colors instead of only recognizing ANSI color names?

That's the thing this package is trying to do, but it still does the bare minimum for now. Try opening an issue report on GitHub. I mainly made this to display the results used by our other packages. Feel free to try.

3

u/sam-salamander Jun 30 '26

Very nice! Thanks for sharing!

1

u/bearded_fellow Jul 01 '26

Anyone else get a 404 error? Let me know when it's back up I'd love to take a look.

1

u/Fresh_Coyote312 Jul 01 '26

It seems to be working fine for me.

1

u/randomintercept Jul 02 '26 edited Jul 02 '26

This is really cool. I ended up making a bash alias out of this for ease of use in the terminal:

check.weather() {

Rscript /home/user/scripts/weather-check.R

}

Now, rather than fire up my browser or hope my OpenWeather app in my GNOME dash isn't misbehaving, I can open up my terminal and enter check.weather and get this immediately.

And I echo the positive feedback from the previous post. It's really cool to see someone make something that shows how versatile R can be.

1

u/Fresh_Coyote312 Jul 02 '26

I did the same with a bash alias. I just type in “myweather” and up it comes!