Permalink
Browse files

monetdb.r 0.6 upgrades

  • Loading branch information...
1 parent f706fb8 commit 6aa594aa2fd7d505a357e59bcc297f4b7fbc2b79 @ajdamico committed Apr 22, 2013
@@ -60,7 +60,8 @@ require(MonetDB.R) # load the MonetDB.R package (connects r to a monet database
# and the monet database will be stored in the MonetDB folder within
# use forward slashes instead of back slashes
-setwd( "C:/My Directory/ACS/" )
+# uncomment this line by removing the `#` at the front..
+# setwd( "C:/My Directory/ACS/" )
# configure a monetdb database for the acs on windows #
@@ -131,7 +132,8 @@ dbport <- 50001
# lines of code to hold on to for all other `acs` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -141,9 +143,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "acs"
dbport <- 50001
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
@@ -534,9 +535,7 @@ for ( year in 2050:2005 ){
key = "idkey" ,
# check.factors = 10 , # defaults to ten
database = monet.url ,
- driver = drv ,
- user = "monetdb" ,
- password = "monetdb"
+ driver = MonetDB.R()
)
# create a sqlrepsurvey complex sample design object
@@ -553,9 +552,7 @@ for ( year in 2050:2005 ){
key = "idkey" ,
# check.factors = 10 , # defaults to ten
database = monet.url ,
- driver = drv ,
- user = "monetdb" ,
- password = "monetdb"
+ driver = MonetDB.R()
)
# save both complex sample survey designs
@@ -603,7 +600,8 @@ monetdb.server.stop( pid )
# lines of code to hold on to for all other `acs` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -613,9 +611,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "acs"
dbport <- 50001
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
@@ -47,7 +47,8 @@ require(MonetDB.R) # load the MonetDB.R package (connects r to a monet database
# lines of code to hold on to for all other `acs` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -57,9 +58,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "acs"
dbport <- 50001
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
@@ -87,7 +87,8 @@ db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
# load the desired american community survey monet database-backed complex sample design objects
-load( 'C:/My Directory/ACS/acs2011_1yr.rda' ) # analyze the 2011 single-year acs
+# uncomment one of these lines by removing the `#` at the front..
+# load( 'C:/My Directory/ACS/acs2011_1yr.rda' ) # analyze the 2011 single-year acs
# load( 'C:/My Directory/ACS/acs2010_1yr.rda' ) # analyze the 2010 single-year acs
# load( 'C:/My Directory/ACS/acs2010_3yr.rda' ) # analyze the 2008-2010 three-year acs
# load( 'C:/My Directory/ACS/acs2010_5yr.rda' ) # analyze the 2006-2010 five-year acs
@@ -96,8 +97,8 @@ load( 'C:/My Directory/ACS/acs2011_1yr.rda' ) # analyze the 2011 single-year acs
# connect the complex sample designs to the monet database #
-acs.m <- open( acs.m.design , driver = drv , user = "monetdb" , password = "monetdb" ) # merged design
-acs.h <- open( acs.h.design , driver = drv , user = "monetdb" , password = "monetdb" ) # household-only design
+acs.m <- open( acs.m.design , driver = MonetDB.R() ) # merged design
+acs.h <- open( acs.h.design , driver = MonetDB.R() ) # household-only design
@@ -52,7 +52,8 @@ require(stringr) # load stringr package (manipulates character strings easily)
# lines of code to hold on to for all other `acs` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -62,9 +63,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "acs"
dbport <- 50001
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
@@ -202,9 +202,7 @@ acs.m.recoded.design <-
key = "idkey" ,
# check.factors = 10 ,
database = monet.url ,
- driver = drv ,
- user = "monetdb" ,
- password = "monetdb"
+ driver = MonetDB.R()
)
@@ -222,7 +220,8 @@ acs.m.recoded.design <-
# unless you've set your working directory elsewhere,
# spell out the entire filepath to the .rda file
# use forward slashes instead of backslashes
-save( acs.m.recoded.design , file = "C:/My Directory/ACS/recoded_acs2011_1yr.rda" )
+# uncomment this line by removing the `#` at the front..
+# save( acs.m.recoded.design , file = "C:/My Directory/ACS/recoded_acs2011_1yr.rda" )
# # # # # # # # # # # # # # # # #
@@ -246,11 +245,12 @@ require(MonetDB.R) # load the MonetDB.R package (connects r to a monet database
# load your new the survey object
-load( "C:/My Directory/ACS/recoded_acs2011_1yr.rda" )
+# uncomment this line by removing the `#` at the front..
+# load( "C:/My Directory/ACS/recoded_acs2011_1yr.rda" )
# connect the recoded complex sample design to the monet database #
-acs.r <- open( acs.m.recoded.design , driver = drv , user = "monetdb" , password = "monetdb" ) # recoded
+acs.r <- open( acs.m.recoded.design , driver = MonetDB.R() ) # recoded
# ..and now you can exactly match the age categories provided by the census bureau at..
# http://www.census.gov/acs/www/Downloads/data_documentation/pums/Estimates/pums_estimates_11.lst #
@@ -52,7 +52,8 @@ require(MonetDB.R) # load the MonetDB.R package (connects r to a monet database
# lines of code to hold on to for all other `acs` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/ACS/MonetDB/acs.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -62,9 +63,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "acs"
dbport <- 50001
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
@@ -92,7 +92,8 @@ db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
# load the desired american community survey monet database-backed complex sample design objects
-load( 'C:/My Directory/ACS/acs2011_1yr.rda' ) # analyze the 2011 single-year acs
+# uncomment one of these lines by removing the `#` at the front..
+# load( 'C:/My Directory/ACS/acs2011_1yr.rda' ) # analyze the 2011 single-year acs
# load( 'C:/My Directory/ACS/acs2010_1yr.rda' ) # analyze the 2010 single-year acs
# load( 'C:/My Directory/ACS/acs2010_3yr.rda' ) # analyze the 2008-2010 three-year acs
# load( 'C:/My Directory/ACS/acs2010_5yr.rda' ) # analyze the 2006-2010 five-year acs
@@ -101,8 +102,8 @@ load( 'C:/My Directory/ACS/acs2011_1yr.rda' ) # analyze the 2011 single-year acs
# connect the complex sample designs to the monet database #
-acs.m <- open( acs.m.design , driver = drv , user = "monetdb" , password = "monetdb" ) # merged design
-acs.h <- open( acs.h.design , driver = drv , user = "monetdb" , password = "monetdb" ) # household-only design
+acs.m <- open( acs.m.design , driver = MonetDB.R() ) # merged design
+acs.h <- open( acs.h.design , driver = MonetDB.R() ) # household-only design
@@ -26,7 +26,8 @@
# in a newly-created "2008" in this directory
# use forward slashes instead of back slashes
-setwd( "C:/My Directory/BSAPUF/" )
+# uncomment this line by removing the `#` at the front..
+# setwd( "C:/My Directory/BSAPUF/" )
# remove the # in order to run this install.packages line only once
# install.packages( "httr" )
@@ -45,7 +46,7 @@ require(httr) # load httr package (downloads files from the web, with SSL and c
# create and set the working directory to a year-specific folder #
# find the current working directory, and add "2008" at the end
-current.year.folder <- normalizePath( paste0( getwd() , "\\2008" ) )
+current.year.folder <- normalizePath( paste0( getwd() , "/2008" ) )
# create a "2008" folder inside the current working directory
dir.create( current.year.folder )
@@ -59,7 +59,8 @@ require(MonetDB.R) # load the MonetDB.R package (connects r to a monet database)
# set this directory to C:/My Directory/BSAPUF/
# use forward slashes instead of back slashes
-setwd( "C:/My Directory/BSAPUF/" )
+# uncomment this line by removing the `#` at the front..
+# setwd( "C:/My Directory/BSAPUF/" )
# set the current year of data to import
@@ -84,7 +85,7 @@ batfile <-
monetdb.server.setup(
# set the path to the directory where the initialization batch file and all data will be stored
- database.directory = "C:/My Directory/BSAPUF/MonetDB" ,
+ database.directory = paste0( getwd() , "/MonetDB" ) ,
# must be empty or not exist
# find the main path to the monetdb installation program
@@ -191,15 +192,12 @@ rxp <- paste0( "./" , year , "/" , year , "_PD_Profiles_PUF.csv" )
-# convert the driver to a monetdb driver
-drv <- dbDriver("MonetDB")
-
# notice the dbname and dbport (assigned above during the monetdb configuration)
# get used in this line
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
# now put everything together and create a connection to the monetdb server.
-db <- dbConnect( drv , monet.url , "monetdb", "monetdb")
+db <- dbConnect( MonetDB.R() , monet.url )
# from now on, the 'db' object will be used for r to connect with the monetdb server
@@ -309,7 +307,8 @@ monet.read.csv(
db ,
rxp ,
paste0( 'rxp' , substr( year , 3 , 4 ) ) ,
- nrows = sapply( rxp , countLines )
+ nrows = sapply( rxp , countLines ) ,
+ nrow.check = 10000
)
@@ -337,7 +336,8 @@ monetdb.server.stop( pid )
# lines of code to hold on to for all other bsa puf monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/BSAPUF/MonetDB/bsapuf.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/BSAPUF/MonetDB/bsapuf.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -347,10 +347,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "bsapuf"
dbport <- 50003
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
-
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
@@ -49,7 +49,8 @@ require(MonetDB.R) # load the MonetDB.R package (connects r to a monet database)
# lines of code to hold on to for the start of all other bsa puf monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/BSAPUF/MonetDB/bsapuf.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/BSAPUF/MonetDB/bsapuf.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -59,9 +60,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "bsapuf"
dbport <- 50003
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# end of lines of code to hold on to for all other bsa puf monetdb analyses #
#############################################################################
@@ -62,7 +62,8 @@ require(downloader) # downloads and then runs the source() function on scripts
# and the monet database will be stored in the MonetDB folder within
# use forward slashes instead of back slashes
-setwd( "C:/My Directory/BRFSS/" )
+# uncomment this line by removing the `#` at the front..
+# setwd( "C:/My Directory/BRFSS/" )
# load the read.SAScii.monetdb() function,
@@ -137,7 +138,8 @@ dbport <- 50004
# lines of code to hold on to for all other `brfss` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/BRFSS/MonetDB/brfss.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/BRFSS/MonetDB/brfss.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -147,9 +149,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "brfss"
dbport <- 50004
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
@@ -336,7 +337,7 @@ for ( year in intersect( years.to.download , 2002:2011 ) ){
# the zipped filename and sas importation script are here:
fn <- "ftp://ftp.cdc.gov/pub/data/brfss/LLCP2011ASC.ZIP"
- sas_ri <- "http://www.cdc.gov/brfss/technical_infodata/surveydata/2011/SASOUT11_LLCP.SAS"
+ sas_ri <- "http://www.cdc.gov/brfss/annual_data/2011/SASOUT11_LLCP.SAS"
# otherwise, if the file to download is 2002..
} else if ( year == 2002 ){
@@ -440,9 +441,7 @@ for ( year in years.to.download ){
key = "idkey" , # sql primary key column (created with the auto_increment line above)
# check.factors = 10 , # defaults to ten
database = monet.url , # monet database location on localhost
- driver = drv , # monet driver location on the local disk
- user = "monetdb" , # username
- password = "monetdb" # password
+ driver = MonetDB.R()
)
# save the complex sample survey design
@@ -482,7 +481,8 @@ monetdb.server.stop( pid )
# lines of code to hold on to for all other `brfss` monetdb analyses #
# first: specify your batfile. again, mine looks like this:
-batfile <- "C:/My Directory/BRFSS/MonetDB/brfss.bat"
+# uncomment this line by removing the `#` at the front..
+# batfile <- "C:/My Directory/BRFSS/MonetDB/brfss.bat"
# second: run the MonetDB server
pid <- monetdb.server.start( batfile )
@@ -492,9 +492,8 @@ pid <- monetdb.server.start( batfile )
dbname <- "brfss"
dbport <- 50004
-drv <- dbDriver("MonetDB")
monet.url <- paste0( "monetdb://localhost:" , dbport , "/" , dbname )
-db <- dbConnect( drv , monet.url , "monetdb" , "monetdb" )
+db <- dbConnect( MonetDB.R() , monet.url )
# # # # run your analysis commands # # # #
Oops, something went wrong.

0 comments on commit 6aa594a

Please sign in to comment.