In R Markdown one is often faced with situations where a value that can vary substantially in automatically pulled out. For example, we might want to pull a p-value out of an linear model object. It’s a chore to have to manually edit p-values so that they conform with reporting conventions (e.g. p < .001).

I’ve written a little function to deal with this issues by taking a value and returning, say, `"= .032"`

or `"< .001"`

, depending on the input value. This could then be used in an R markdown file to automatically round a value in the way you want without anything having to be done manually. For example, you could pull out and round the p-value from a t-test with `*p* `r cutoff(t.test(x, y, paired = TRUE)[[3]])`

.

For a more detailed guide to how this function can be customised to work with various statistics head over to Github.