library(tidyverse)
# Make yard size, the presence/absence of a home garden, and attitudes toward the
# environment all correlated with each other. Home garden will be binary, so I split
# it based on some threshold later. Attitudes toward the environment will be on a
# scale of 1-10, so I rescale and ceiling it later
mu <- c(yard_size = 20000, home_garden = 30, attitude_env = 70)
stddev <- c(yard_size = 10000, home_garden = 15, attitude_env = 40)| <?php | |
| /** | |
| * This recipe adds billing fields to the Membership Profile page. | |
| * | |
| * It is intended for use with the Register Helper Add On: | |
| * https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/ | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. |
| # a combination of | |
| # https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/15373917#15373917 | |
| # https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/7585599#7585599 | |
| # https://stackoverflow.com/questions/47044068/get-the-path-of-current-script/47045368#47045368 | |
| # https://stackoverflow.com/questions/53512868/how-to-automatically-include-filepath-in-r-markdown-document/53516876#53516876 | |
| stub <- function() {} | |
| thisPath <- function() { | |
| cmdArgs <- commandArgs(trailingOnly = FALSE) | |
| if (length(grep("^-f$", cmdArgs)) > 0) { | |
| # R console option |
| ## load rtweet | |
| library(rtweet) | |
| ## store bounding box coordinates for state of nevada | |
| nv <- c(-120.00647, 35.00186, -114.03965, 42.00221) | |
| ## initialize output vector and Midwestern 'ope' counter | |
| s <- list() | |
| ope <- 0L |
| # What's the most natural way to express this code in base R? | |
| library(dplyr, warn.conflicts = FALSE) | |
| mtcars %>% | |
| group_by(cyl) %>% | |
| summarise(mean = mean(disp), n = n()) | |
| #> # A tibble: 3 x 3 | |
| #> cyl mean n | |
| #> <dbl> <dbl> <int> | |
| #> 1 4 105. 11 | |
| #> 2 6 183. 7 |
| # theme options based on hour of day ------------------------------------------- | |
| # based on https://github.com/rstudio/rstudio/issues/1579 | |
| setHook("rstudio.sessionInit", function(chooseTheme) { | |
| if (chooseTheme) { | |
| if (as.numeric(format(as.POSIXct(Sys.time(), format = "%H:%M:%S"), "%H")) %in% c(0:5, 21:23)) { | |
| if (rstudioapi::getThemeInfo()$editor != "Solarized Dark") rstudioapi::applyTheme("Solarized Dark") | |
| } else { | |
| if (rstudioapi::getThemeInfo()$editor != "Solarized Light") rstudioapi::applyTheme("Solarized Light") | |
| } | |
| } |
| local({ | |
| ## Put everything in a separate environment and attach that | |
| ## environment. Re-use the existing one from the search path it | |
| ## it's available, so that re-executing this file doesn't add a | |
| ## new environment to the search path every time. | |
| custom_env <- tryCatch(as.environment("rct_custom_env"), | |
| error=function(...) { | |
| attach(NULL, name="rct_custom_env") | |
| as.environment("rct_custom_env") |
I'm a long-time fan of the graph visualization tool Gephi and since Wikimania 2019 I got involved with Wikidata. I was aware of the Gephi plugin "Semantic Web Importer", but when I check it out, I only find old tutorials connecting to DBpedia, not Wikidata:
- "Visualising Related Entries in Wikipedia Using Gephi" by Tony Hirst, 2012-07-03
- "Letβs Play Gephi: Dbpedia, RDF, Sparql and your favorite Actors" by Matthieu Totet, 2015-10-06
- ["Gephi tutorials: Semantic Web Importer" by Matthieu
| # Find Packages Used in a Project Using Regular Expressions RegEx | |
| list_of_Rmd_R <- c( | |
| list.files(path = here::here(), | |
| pattern = "\\.Rmd|.R$", # find files ending with .Rmd and .R | |
| full.names = TRUE | |
| ), | |
| list.files(path = here::here("childRmd"), | |
| pattern = "\\.Rmd|.R$", |
When you use knit_expand it appears that the inclusion of the Rmd is done on the first pass, and then the complete document evaluated. This means that a Rmd block referenced in loop with knit_expand will only evaluate changing variables at their last value.
This can be worked around by passing the literal value of the variable at the time of the knit_expand with {{var}} syntax.
This is documented in the knitr_expand docs, but less clear (to an R noob like me) for embedded documents rather than strings.