James A Campbell

@rtbecard.bsky.social

(he/him) Former bird dude, current fish guy; currently based in Berlin. I'm into ecology, stats, bioacoustics, and artificial light. Currently working as part of this ETN: https://www.msca-ribes.eu/

I wrote up my solution for figure scaling in rmarkdown. `fig.width` and `fig.height` set the output size and the new `scale` parameter scales the figure contents. Paste the code for the option hook in the first chunk, and the scale parameter will be available in all the following chunks. #rstats

Plots with variable scale factors and constant size.

```{r, fig.width=2, fig.height=2}
plot(pressure)
```
```{r, fig.width=2, fig.height=2, scale = 0.5}
plot(pressure)
```Image of output from rmarkdown figure scaling example```{r setup, include=FALSE}
# Set chunk hook
# This will automatically adjust the figure parameters for you
knitr::opts_hooks$set(fig_scale = function(options) {
  
  # --- Store out_width
  # HTML and latex output require different units
  out_width <- switch(knitr::opts_knit$get("rmarkdown.pandoc.to"),
    # html requires pixels
    "html" = sprintf("%ipx", options[["fig.width"]] * options[["dpi"]]),
    # Latex requires inches
    "latex" = sprintf("%.fin", options[["fig.width"]])
  )
  
  # Calculate new fig width and height values
  fig_width <- options[["fig.width"]]/options[["scale"]]
  fig_height <- options[["fig.height"]]/options[["scale"]]
  
  # Store chunk options
  options$out.width = out_width
  options$fig.height = fig_height
  options$fig.width = fig_width
  # Return the modified options
  return(options)
})

# Set figure scaling hook for following chunks
knitr::opts_chunk$set(scale = 0.8, fig_scale = TRUE)
```

Dear #rstats, is there a repository that shows the build scripts for all the libraries bundled in RTools distributions? I had an especially awful time trying to link to RTools' libsndfile (I gave up and compiled my own). Would be helpful if I could see how these libraries are configured.

#rstats, is there a reason why R doesn't have a special `end` keyword for indexing? Like, `vec[(end-10):(end)]` for selecting the last 10 elements (as opposed to `n=length(vec); vec[(n-10):n]`). Or some reasonable way to refer to the last index? I feel like this is some low-hanging fruit

I finally found a nice solution for scaling figures in rmarkdown: Setup a chunk options hook which dynamically sets the out.width, fig.width and fig.height options. fig.width=7, scale=0.8 now returns a figure 7 in wide, but the contents will be scaled down by a factor of 0.8. #Rstats

Screenshot of codeblock:

# Set chunk hook
# This will automatically adjust the figure parameters for you
knitr::opts_hooks$set(fig_scale = function(options) {
  # Calculate out_width
  out_width <- sprintf("%.fin", options[["fig.width"]])
  fig_width <- options[["fig.width"]]/options[["scale"]]
  fig_height <- options[["fig.height"]]/options[["scale"]]
  # Store chunk options
  options$out.width = out_width
  options$fig.height = fig_height
  options$fig.width = fig_width
  return(options)
})

# Set figure scaling hook
knitr::opts_chunk$set(scale = 0.8, fig_scale = TRUE)

# Set random seed for reproducible plots
set.seed(1)Example chunk where fig.width=7 and fig.height=5The resulting figure which has a width of 7 inches and the contents are scaled by a factor 0.8, so it matches well with rest of the document's text size.

At the end of the term I asked my college creative wriing students to submit anonymous thoughts on AI. No real surprises: Mood ranges from resignation to despair, capitulation from embittered erosion of standards to total, feelings of betrayal from deep to furious. 1/

My life's choices have left me in a place where I have to bounce back and forth between writing equations in LaTeX and writing them in Word's "equation editor." What I have done to deserve this.

Ecologists I need a favor! 🌎🌍🌏 I am teaching a GIS class for freshmen. I want to zoom in for like 15-20 min with other ecologists that are using drones, uav, collars, biologgers, telemetry, or any type of sensors to study wildlife. 1️⃣

🧵 Oxford Institute for Energy Studies often cited in UK media stories on oil and gas But how independent is it? Its staff includes director of major sanctioned Russian gas firm and researcher accused of pushing Kremlin talking points New on Democracy for Sale: open.substack.com/pub/democrac...

The Oxford energy institute with a Kremlin problem

The Oxford Institute for Energy Studies is cited across UK media as an independent expert on oil and gas. Now its Russian ties are under scrutiny.

open.substack.com

Dear #Rstats , I know someone who studies/works in psychology, and they are interested in getting more into the statistics side of things. Is there a really good psychology-focused statistics conference that they should keep on their radar?