') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - harrelfe/rscripts: Miscellaneous R functions, R report templates, and complete example R analysis scripts in Quarto and RMarkdown · GitHub
Skip to content

Latest commit

History

411 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

rscripts

R Scripts: Templates, Examples of Analyses using knitr with Rmarkdown or LaTeX, Interactive RStudio Demonstrations | Contents Directory

This is for use with the R function getRs in the R Hmisc package for listing available scripts, downloading a selected script, and opening it in the RStudio script editor window.

The special file contents.md lists all the available files and short descriptions for them. It should not be edited, as it is auto-generated by createContents.r. contents.md is used when getRs is called with no arguments, to give the user a list of available scripts and their descriptions.

The Rmarkdown scripts included here use a template that makes the result part of a reproducible research process by documenting the versions of R and attached packages at the end of the report. They make use of the Hmisc package's knitrSet function. When running Rmarkdown, call knitrSet(lang='markdown'). knitrSet gets rid of ## at the start of R output lines, and makes it easy to specify things like figure sizes in knitr chunk headers. It also causes annoying messages such as those generated from attaching R packages to be put in a separate file messages.txt rather than in the report.

contents.md is generated from titles, major and minor categories, and types (R, R Markdown) that are at the top of each script. R Markdown scripts must have suffix Rmd and have the following information between lines containing --- and after the output: section: major, and minor (optional). Scripts that fall under multiple categories have those category descriptions separated by semicolons. See descriptives.Rmd for an example. Regular R scripts must have suffix r and have the following in the top lines of the script (again, minor is optional):

# title: Title of Script with Purpose, etc.
# major: major category 1; major category 2 ...
# minor: minor category 1; minor category 2 ...

See introda.r for an example.

Some possible values for major categories are listed below.

Major CategoryComments
curve fitting
descriptive statistics
graphics
statistical pitfalls
introductionIntroduction to R
regression modeling
statistical tests
ABDProblems from Analysis of Biological Data, 2nd edition, by Whitlock and Schluter

Some possible values for minor categories are listed below.

Minor CategoryComments
ordinary least squaresLinear Model
unadjusted comparisons
categorization

To request the addition of new categories open an issue for this GitHub project.

About

Miscellaneous R functions, R report templates, and complete example R analysis scripts in Quarto and RMarkdown

Resources

Stars

92 stars

Watchers

11 watching

Forks

Releases

Packages

Contributors

Languages