11/9/2022 0 Comments Conditional inline r![]()
A positive test still means we might not have the disease, and testing negative might mean we have it, though hopefully with very little likelihood. When we go to the doctor to test for a disease (say tuberculosis or HIV or even, more commonly, strep throat and flu), we get a yes or no answer. #Conditional inline r movieSuch card counting and conditional probabilities (what's the likelihood of each hand, given what I have seen) is one of the (frowned upon) strategies for trying to beat the casinos in blackjack and poker (see the movie 21 for a Hollywood version of real-life card counting in casinos). Inveterate bridge players like my dad would keep track of cards as they got exposed in the pile, for that (and the bids) provided information about the likelihoods of what hand each player had. Some more examples of where we might encounter such conditional probabilities: What we will explore is the concept of conditional probability, which is the probability of seeing some event knowing that some other event has actually occurred. That's the subject for a future post on Bayesian statistics. This post won't speak to how these probabilities are updated. After every game the team plays, these probabilities change based on whether they won or lost. From the beginning of each season, fans start trying to figure out how likely it is that their favorite team will make the playoffs. For example, the NFL season is rife with possibilities. #Conditional inline r codeBy including an empty code chunk in the email document, also labeled orders_inventory, that section of the original report gets reused.In addition to regular probability, we often want to figure out how probability is affected by observing some event. ![]() These charts are the output of a code chunk from the main report called orders_inventory. It also contains inventory burndown charts for each of the three color-ways. ![]() #Conditional inline r updateThe Orders and Inventory Update email has a different banner image and includes running shop totals for orders and units sold which were tabulated in the main Cookie Cutter Shop Report document. Now, instead of suppressing email in the else block, an additional render function points to a different email document: inventory-update.Rmd. The code chunk in the main report is updated as follows: In this case, I still want to get an alert email if my shop inventory is low but if inventory is stable, I want to receive a general update on my basic shop statistics. But now that blastula provides a function to render an email from a separate R Markdown document, it follows that we may also want to define conditional logic for attaching either/or emails. The option to send or suppress is useful, especially when you don’t want to flood someone’s inbox with repetitive alerts. #Conditional inline r fullSee the full code Gist: Conditional Suppression Example.This example includes a banner image, some plain text, a markdown header, and an unordered list of items that include inline R code defined in the original (parent) report. The rest can be crafted like a regular R Markdown document. To define an email message, the YAML header output needs to be of type blastula::blastula_email. This is where the email body contents are defined: The render_connect_email function references an additional file, inventory-alert.Rmd. The functions render_connect_email, attach_connect_email, and suppress_scheduled_email are all available in the blastula package. Low_inventory is a boolean that gets set to TRUE when the inventory count for any individual color drops into the alert threshold (<= 2). ![]() To achieve this behavior, a code chunk is added to the bottom of the main report which contains logic to either attach or suppress an email based on the value of low_inventory. Solution Components #Įvery time the report runs, it evaluates the orders and inventory data, then determines whether or not to trigger a custom email event. If inventory is getting low for a specific color, we want to receive an alert so the 3D printer can start creating a new batch of cookie cutters overnight. They are printed in batches of nine, and each batch takes about five hours to create. The Etsy shop sells one style of cookie cutter (R logo shaped) in three color-ways: Purple, Black, and Red. Goal: Receive an automated alert email whenever inventory drops below a warning threshold Our goal is to create an R Markdown report that tracks basic statistics for orders, sales and inventory levels, while also sending alerts when inventory gets low. Scenario: Every day new orders flow in and inventory is depleted. This article uses the example of an Etsy shop to demonstrate an R Markdown-based conditional custom email workflow using RStudio Connect. Customized Conditional Emails with RStudio Connect # ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |