Skip to content

Instantly share code, notes, and snippets.

@javieroot
javieroot / RPostgreSQL.R
Created August 12, 2018 19:32
Conexión a base de datos de PostgreSQL desde R
# Una vez teniendo lista la instalación de PostgreSQL y R:
# En el terminal:
pacman -S postgresql-libs
# Dentro de R instalar el paquete RPostgreSQL
install.packages("RPostgreSQL")
# Una vez realizado lo anterior se procede a realizar la conexión con:
@javieroot
javieroot / shiny_server.R
Last active August 12, 2018 19:36
Para poder instalar shiny server
# Al instalar el paquete shiny aparace un error de dependenca de la libería later
# al tratar de instalarla antes aparece lo mismo, si se instala de github se instala
# sin problemas:
devtools::install_github('r-lib/later')
# Instalación de shiny server
aurman -S shiny-server
# Los ejemplo de shiny no están cuando se realiza la instalación desde aur
# Si se requieren hay que descargarlos de github:
@javieroot
javieroot / install_bumblebee.sh
Last active July 7, 2019 18:57
Instalación y puesta en marcha de bumblebee para que funcionen ambas tarjetas de gráficos en Arch Linux con los drivers open source
# El funcionamiento de bumblebee es bajo demanda
# Fuentes:
# https://wiki.archlinux.org/index.php/Bumblebee_(Español)
# https://wiki.archlinux.org/index.php/NVIDIA_(Español)
# https://wiki.archlinux.org/index.php/Nouveau_(Español)
# https://antergos.com/wiki/es/hardware/bumblebee-for-nvidia-optimus/
# Editar el archivo /etc/mkinitcpio.conf
# poner MODULES=(nouveau) no MODULES="nouveau" como mencionan en algunos lugares como la wiki
sudo pacman -S bumblebee mesa xf86-video-intel bbswitch xf86-video-nouveau
@javieroot
javieroot / .screenrc-main-example
Last active February 2, 2018 19:10 — forked from ChrisWills/.screenrc-main-example
A nice default screenrc
# GNU Screen - main configuration file
# All other .screenrc files will source this file to inherit settings.
# Author: Christian Wills - cwills.sys@gmail.com
# Allow bold colors - necessary for some reason
attrcolor b ".I"
# Tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
@javieroot
javieroot / tryCatch.R
Created January 9, 2018 15:30 — forked from x-raizor/tryCatch.R
tryCatch in R
urls <- c(
"http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html",
"http://en.wikipedia.org/wiki/Xz",
"xxxxx"
)
readUrl <- function(url) {
out <- tryCatch(
{
# Just to highlight: if you want to use more than one
# R expression in the "try" part then you'll have to
@javieroot
javieroot / tryCatch.R
Last active January 10, 2018 22:39 — forked from nassimhaddad/tryCatch.R
using trycatch
result = tryCatch({
is.numeric(1)
# return(TRUE)
# no poner return, ya que da error, solo poner TRUE al final si se quiere
# una salida TRUE
# TRUE
# return(0)
0
}, warning = function(w){
message("Warning")
@javieroot
javieroot / updateClob.R
Last active June 14, 2018 22:35
Actualiza tablas de Oracle con campos muy grandes, del tipo de dato clob
updateClob <- function(bd, tabla, condiciones = list(), actualizacion = list()){
# Esta función no se recomienda utilizarla cuando el número de registros a
# actualizar es considerablemente grande, ya que descarga la información,
# la actualiza en R, la borra en Oracle y luego la vuelve a subir.
#
# La parte principal de esta función es:
# attr(datosOriginales$', names(conteoCaracteres), ', "ora.type") <- "clob"'
# que solo está disponible en la función dbWriteTable
#
@javieroot
javieroot / main.Rnw
Created December 2, 2017 22:43 — forked from yihui/main.Rnw
use knit() with a loop to write reports for subsets of data
\documentclass{article}
\begin{document}
<<run-all, results='hide', message=FALSE>>=
library(xtable)
out = NULL
for (g in unique(mtcars$gear)) {
out = c(out, knit_child('template.Rnw', sprintf('gear-%s.tex', g)))
}
@javieroot
javieroot / rcpp_examples.R
Created December 2, 2017 21:58
Some sample Rcpp code
library(Rcpp)
# Simple addition
add_r <- function(x, y, z) {
sum = x + y + z
return(sum)
}
cppFunction(
"int add_c(int x, int y, int z) {
@javieroot
javieroot / transpose_dataframe.R
Created December 2, 2017 20:25 — forked from danielecook/transpose_dataframe.R
Transpose data frame R
tFrame <- function(x) {
x <- t(x)
row_names <- row.names(x)[2:length(row.names(x))]
col_names <- x[1,]
x <- tbl_df(as.data.frame(x[2:nrow(x),]))
colnames(x) <- col_names
rownames(x) <- row_names
x <- dplyr::add_rownames(x, var = "strain")
x
}