Skip to content

Instantly share code, notes, and snippets.

View gorkang's full-sized avatar

Gorka Navarrete gorkang

View GitHub Profile
@strengejacke
strengejacke / .lintr
Last active October 29, 2024 23:21
VS Code setup for R
// save to windows-user directory
linters: with_defaults(object_name_linter = NULL,
object_length_linter(50),
commented_code_linter = NULL,
object_usage_linter = NULL,
line_length_linter(120),
cyclocomp_linter = cyclocomp_linter(50))
@christophsax
christophsax / covid-19.md
Last active April 5, 2020 20:17
Coronavirus disease: new infections and total cases
library(tidyverse)
library(anytime)

# Data Repo Johns Hopkins CSSE
# https://github.com/CSSEGISandData/COVID-19
url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
dta_raw <- read_csv(url, col_types = cols()) %>%
  select(-Lat, -Long)
@jbkunst
jbkunst / script.R
Last active April 1, 2019 15:38
UF SII CHILE
library(tidyverse)
library(rvest)
get_uf <- function(y) {
# y <- 2016
message(y)
seleccionador <- ifelse(y <= 2012, first, last)
@AWKruijt
AWKruijt / fetchCitingRecords
Last active March 21, 2019 21:57
quickly whipped up something to fetch citing articles from pubmed
# essentially same as before but now restructured into a function: getCitingPMIDs()
getCitingPMIDs <- function(PMID) {
lines <- readLines(paste0("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?dbfrom=pubmed&linkname=pubmed_pubmed_citedin&id=", PMID)) # construct quering URL using the PMID parameter in resTargetRecord, and fetch its contents into object lines
citingPMIDs <- sub("^.*(<Id>)(.*)(</Id>)", "\\2", lines[grep("<Id>", lines)]) # filter out lines in lines that contain <Id> and then filter out the content between <Id> and </Id>.Store in object citingPMIDs
citingPMIDs <- citingPMIDs[-1] # remove first entry in citingPMIDs, which is the target record
return(citingPMIDs)
}
@crsh
crsh / plot_dependencies.R
Last active January 15, 2021 08:35
Plots the network of package dependencies
#' Plot network of package dependencies
#'
#' @param pkg package description, can be path or package name. See \code{\link[devtools]{as.package}} for
#' more information.
#'
#' @details The resulting plot visualizes the network of package dependencies. If you are trying to cut down
#' on package dependencies look for big red dots that represent a lot of upstream but few downstream
#' dependencies.
#' @import ggplot2
#' @export
@richarddmorey
richarddmorey / arbitrary_prior.R
Last active March 21, 2022 20:26
Functions for computing the Bayes factor t test for an arbitrary prior on effect size
## This function computes the (normalized) marginal likelihood.
## You will not use this function directly.
p.y.alt = function(t.stat, N, log.prior.dens,lo=-Inf,up=Inf,...){
normalize = integrate(function(delta,...){
exp(log.prior.dens(delta, ...))
}, lower = lo, upper = up, ...)[[1]]
py = integrate(function(delta,t.stat,N,...){
exp(
dt(t.stat, N - 1, ncp = delta*sqrt(N), log = TRUE) +
@mbarnkob
mbarnkob / RArticleNetwork.R
Last active March 12, 2018 17:46
R code for generating a network of referring articles from pubmed. More info here: http://mikebarnkob.dk/2015/generating-an-article-network-using-rentrez-and-igraph-in-r/
#Article Network ver 2
#============================
# This program will scrape all citing articles surrounding one main article and
# create: 1) a list of most cited articles, 2) lists of main authors, 3) network of articles
# Mike Barnkob, December 28th 2015.
# www.mikebarnkob.dk
#Background and references
#1. https://cran.r-project.org/web/packages/rentrez/vignettes/rentrez_tutorial.html#advanced-counting