title | author | date | output | ||||
---|---|---|---|---|---|---|---|
Reprex: rendering fails or incomplete for list of pointblank tables in rmarkdown documents |
Elliot Gould |
08/03/2021 |
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remotes::install_github("egouldo/ManyEcoEvo") # install latest ManyEcoEvo | |
library(tidyverse) | |
library(ManyEcoEvo) | |
library(metafor) | |
library(remotes) | |
# ------ define data extraction / plotting functions ------ | |
get_forest_plot_data <- function(model){ |
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 83 columns, instead of 58 in line 1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Site,Habitat,Season,Chgouldii,Chmorio,CG/Mormlp,MormII,Mschocean,Nyctspp,Mmacropus,Nspp/Mmacr,Scotspp.,Taustralis,Vdarlingtoni,Vregulus,Vvulturnus,Unidentified,BatSpecies,BatActivity,Col,Dip,Eph,Hem,Lep,Hym,Tri,Manto,Psoc,Orth,Neur,Derm,Bla,Iso,Odo,Plec,Insectabundance,TotalOrder,Moon,NatEx,Bioregion,Size,SQQ,Water Depth,Imp 5km,Imp2km,Imp1km,Imp500m,NDVI2km,NDVI1km,NDVI500m,Trees 5km,Trees2km,Trees1km,Trees500m,House500,House1km,House2km,House5km,Light500m,Light1km,Light2km,Light5km,Road500m,Road1km,Road2km,Road5km,Distriver,Distwetland,Distwater,Distbushland,Aqvegcov,EphemVeg,TreeCoverage,TreesLarge>20dbh.plot,TreesSmall<20dbh.plot,Trees total.plot,Shrubs.plot,Hollows.total,Otherroostsnumber.total,TotalRoost,Distance1sttree,Temp,Humidity | |
Albert Park,1,1,151,0,6,0,0,10,0,10,8,1,0,0,1,8,7,185,6,20,48,0,13,1,16,0,0,0,0,0,0,0,0,0,104,6,2,2,1,508500,6.352532434,4,307.4648102,319.4008886,451.1150505,1693.27663,0.084813599,0.306702905,0.418516578,154467,16004,8789,1749,13147478.69,52767347.28,135155830.3,542156685 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Reprex: rendering fails or incomplete for list of pointblank tables in rmarkdown documents" | |
author: "Elliot Gould" | |
date: "08/03/2021" | |
output: | |
html_document: | |
keep_md: yes | |
--- | |
```{r setup, include=FALSE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gam_fun <- function(data, rabbit_var = c("rabbitwarrens", "warrenspretreatment"), df = integer(length = 1)){ | |
if(rabbit_var == "rabbitwarrens"){ | |
f <- substitute(gam(peren_chen_pc_cover ~ s(winterrain, df) + s(otherrain, df) + year + site + s(warrenspretreatment, df) + s(regionalroos, df) + landsystem, data=data, family=gaussian)) | |
} else{ | |
f <- substitute(gam(peren_chen_pc_cover ~ s(winterrain, df) + s(otherrain, df) + year + site + s(rabbitwarrens, df) + s(regionalroos, df) + landsystem, data=data, family=gaussian)) | |
} | |
eval(f) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://github.com/ateucher/useful_code/blob/master/R/numbers2words.r | |
numbers2words <- function(x){ | |
## Function by John Fox found here: | |
## http://tolstoy.newcastle.edu.au/R/help/05/04/2715.html | |
## Tweaks by AJH to add commas and "and" | |
helper <- function(x){ | |
digits <- rev(strsplit(as.character(x), "")[[1]]) | |
nDigits <- length(digits) | |
if (nDigits == 1) as.vector(ones[digits]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_latex <- function(f){ | |
knitr::knit(f, 'tmp-outputfile.md'); | |
newname <- paste0(tools::file_path_sans_ext(f), ".tex") | |
mess <- paste('pandoc -f markdown -t latex -p -o', shQuote(newname),"tmp-outputfile.md") | |
system(mess)} | |
# The function above takes an `Rmd` file as its input, knits the file to `md`, and then converts it to `TeX` by calling pandoc from the command-line. The secret ingredient lies in the pandoc call... When knitting using Rstudio, Rstudio calls the pandoc standalone `-s` flag when it compiles the pdf. This generates a 'standalone' document, i.e. one that contains latex preamble. This is obviously necessary when you want to view the PDF, but is problematic when you want to generate a latex fragment only from Rmd. | |
# I instead sought to generate a latex 'fragment' from `Rmd` with knitr, that can be later incorporated into a main TeX file. So the solution was simply to create a pandoc command line call that omits the `-s` standalone flag. I achieved this by calling pandoc from R with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: http://www.cookbook-r.com/Manipulating_data/Converting_between_data_frames_and_contingency_tables/#countstocases-function | |
# Convert from data frame of counts to data frame of cases. | |
# `countcol` is the name of the column containing the counts | |
countsToCases <- function(x, countcol = "Freq") { | |
# Get the row indices to pull from x | |
idx <- rep.int(seq_len(nrow(x)), x[[countcol]]) | |
# Drop count column | |
x[[countcol]] <- NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## FUNCTION - KfoldCASEFILE | |
# splits an R object of a case file into 5 Folds (When K is set to 5) | |
# Outputs the object into five pairs (When K = 5) of training and test case files in .cas format | |
# The input case file object must contain a column called "IDnum" | |
KfoldCASEFILE<-function(CaseFile, seed,k, path1, path2){ | |
# Renumber the IDnum column by order IF the case file is missing a number in a sequence | |
CaseFile<-IDnumOrdered(CaseFile) | |
#1. Setting the folds | |
#2. Join the folds to the casefile object by dplyr::innerjoin (by cols are index in folds and idnum in casefile object) | |
set.seed(seed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##' Modifies 'data' by adding new values supplied in newDataFileName | |
##' | |
##' newDataFileName is expected to have columns | |
##' c(lookupVariable,lookupValue,newVariable,newValue,source) | |
##' | |
##' Within the column 'newVariable', replace values that | |
##' match 'lookupValue' within column 'lookupVariable' with the value | |
##' newValue'. If 'lookupVariable' is NA, then replace *all* elements | |
##' of 'newVariable' with the value 'newValue'. | |
##' |