Skip to content

Instantly share code, notes, and snippets.

View tomsing1's full-sized avatar

Thomas Sandmann tomsing1

View GitHub Profile
@tomsing1
tomsing1 / glue_sql_quoting.R
Created April 19, 2024 17:33
Controlling quoting by the glue::glue_sql() function
library(glue)
library(RSQLite)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
var = "test"
glue_sql("{var}", .con = con) # <SQL> 'test'
glue_sql("{`var`}", .con = con) # <SQL> `test`
glue_sql("{DBI::SQL(var)}", .con = con) # <SQL> test (unquoted)
glue_sql("`{var}`", .con = con) # <SQL> `'test'` NOT USEFUL
@tomsing1
tomsing1 / conditionalPanel_usage_in_module.R
Last active April 7, 2024 19:33
Modularized shiny app using conditional panels (modified from the shiny::conditionalPanel help page)
# The following code is based on the shiny::conditionalPanel() help page. The `ui` and `server`
# components have been compartmentalized into the `mod_histogram` module. The `histogramApp`
# function shows an example of using this module.
# Note that the `ns = ns` argument needs to be passed ot the conditionalPanel() call.
library(shiny)
mod_histogram_ui <- function(id){
ns <- NS(id)
fluidPage(
@tomsing1
tomsing1 / goofyfs.md
Created July 14, 2020 16:18
Mounting an S3 bucket as a folder on Mac OS X

This document shows how to mount an AWS S3 bucket on Mac OS X using goofyfs.

The first three steps illustrate how to use goofys

  1. Install goofyfs via brew
brew cask install osxfuse
brew install goofys
@tomsing1
tomsing1 / nextflow_tower.md
Created February 15, 2021 20:15
Setting up nextflow tower locally

Installing Nextflow on a Mac

  • Install JAVA 8
 brew install adoptopenjdk8
  • Install Nextflow: curl https://get.nextflow.io | bash in the current directory
  • Optional: Move the nextflow binary to a directory that is in the PATH.
@tomsing1
tomsing1 / biosample_attributes.R
Created January 25, 2024 17:22
Retrieve sample attributes from EBI's ENA repository in JSON format
library(glue)
library(httr)
library(jsonlite)
library(xml2)
#' Query ENA's REST API for information about records
#'
#' @param accessions Character vector of one or more ENA record identifiers
#' @return An `xml_document` object
get_records <- function(accessions) {
@tomsing1
tomsing1 / order_input.R
Created January 16, 2024 04:54
Reordering the levels of categorical variables in a shiny app with shinyjqui
library(palmerpenguins)
library(shiny)
library(shinyjqui)
categories <- colnames(penguins)[vapply(penguins, is.factor, logical(1))]
server <- function(input, output) {
lapply(categories, \(category) {
output[[category]] <- renderPrint({ print(input[[category]]) })
})
@tomsing1
tomsing1 / image_placeholder.R
Created January 8, 2024 19:09
Create an image tag pointing to a random picture from Lorem Picsum
#' Create an image tag with an example image
#'
#' @param width Scalar integer, the width of the image
#' @param height Scalar integer, the height of the image
#' @param title Scalar character, the title of the image
#' @return A `shiny.tag` with the URL to a random image from
#' [Lorem Picsum](https://picsum.photos/)
#' @export
#' @importFrom htmltool tags
#' @importFrom checkmate assert_count assert_character
@tomsing1
tomsing1 / pyenv.md
Last active December 28, 2023 00:16
Using pyenv to manage multiple python versions & virtual environments

There is a lot of confusing information about virtual environments in python out there, in part because the tool chain has evolved over many years.

I decided to follow the advice of Real python and The hitchhiker's guide to python and manage both multiple python versions and multiple virtual environments with pyenv

@tomsing1
tomsing1 / quarto_webr_example.qmd
Created November 19, 2023 17:32
Quarto markdown file that uses the quarto-webr extension to run R code in the browser
---
title: "Embedding R into Quarto documents with quarto-webr"
subtitle: "Example: intersecting differential expression results"
author: "Thomas Sandmann"
date: '2023/11/18'
format: html
engine: knitr
webr:
show-startup-message: true
packages: ['ggvenn', 'huxtable']
@tomsing1
tomsing1 / luigi_first_steps.md
Last active October 7, 2023 13:23
First steps with the Luigi workflow manager

First steps with the Luigi workflow manager

As an introduction into Luigi, I am following this tutorial with some modifications, e.g. installation using conda.

The problems and solutions described in the examples below have led to the development of sciluigi,