Skip to content

Instantly share code, notes, and snippets.

@vladiim
Created July 6, 2012 06:22
Show Gist options
  • Select an option

  • Save vladiim/3058385 to your computer and use it in GitHub Desktop.

Select an option

Save vladiim/3058385 to your computer and use it in GitHub Desktop.
R PostGres
# https://github.com/eBioGit/R-by-example/blob/master/database%20interface/RpostgreSQL.R
############# EXEMPEL PostgreSQL ##############
# Calling R in command mode
# R --no-save < RpostgreSQL.R
library("DBI")
library("RPostgreSQL")
############## SETS LOGIN INFORMATION ##############
#
# Sets database login information for the other scripts
#
source("../.gitignore/login.R")
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, user=login$user, password=login$password, dbname=login$dbname)
res <- dbSendQuery(con, "select * from genotype")
chunk <- fetch(res, n = 100) # Return only 100 rows
# look at the results
chunk
class(chunk)
chunk$index_nr
data <- dbGetQuery(con, "select * from genotype") # return whole table
plot(data$type_nr,
xlab="Sample space",
ylab="Genotype Nr",
main="Genotype distribution of ASFV Sardinia")
dbClearResult(res)
dbDisconnect(con)
dbUnloadDriver(drv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment