Skip to content

Commit

Permalink
RCurl removal downloader addition setwd and other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdamico committed Feb 12, 2013
1 parent c6544bc commit d77350d
Show file tree
Hide file tree
Showing 49 changed files with 228 additions and 283 deletions.
25 changes: 5 additions & 20 deletions American Community Survey/2005-2011 - download all microdata.R
Expand Up @@ -50,9 +50,9 @@
# it's running. don't believe me? check the working directory (set below) for a new r data file (.rda) every few hours.



require(downloader) # downloads and then runs the source() function on scripts from github
require(sqlsurvey) # load sqlsurvey package (analyzes large complex design surveys)
require(RMonetDB) # load the RMonetDB package (connects r to a monet database)
require(RMonetDB) # load the RMonetDB package (connects r to a monet database)


# set your ACS data directory
Expand All @@ -64,25 +64,10 @@ require(RMonetDB) # load the RMonetDB package (connects r to a monet database)
setwd( "C:/My Directory/ACS/" )



#######################################################
# function to download scripts directly from github.com
# http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)

# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
}
#######################################################

# load the windows.monetdb.configuration() function,
# which allows the easy creation of an executable (.bat) file
# to run the monetdb server specific to this data
source_https( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/windows.monetdb.configuration.R" )
source_url( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/windows.monetdb.configuration.R" )


# create a folder "MonetDB" in your current working directory.
Expand Down Expand Up @@ -666,9 +651,9 @@ db <- dbConnect( drv , monet.url , user = "monetdb" , password = "monetdb" )


# unlike most post-importation scripts, the monetdb directory cannot be set to read-only #
winDialog( 'ok' , paste( "all done. DO NOT set" , getwd() , "read-only or subsequent scripts will not work." ) )
message( paste( "all done. DO NOT set" , getwd() , "read-only or subsequent scripts will not work." ) )

winDialog( 'ok' , "got that? monetdb directories should not be set read-only." )
message( "got that? monetdb directories should not be set read-only." )


# for more details on how to work with data in r
Expand Down
4 changes: 3 additions & 1 deletion Area Resource File/2011-2012 arf - analysis examples.R
Expand Up @@ -35,7 +35,9 @@
# after running the program described above
# use forward slashes instead of back slashes

setwd( "C:/My Directory/ARF/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/ARF/" )
# ..in order to set your current working directory


# load the 2011-2012 ARF data file
Expand Down
31 changes: 10 additions & 21 deletions Area Resource File/2011-2012 arf - download.R
Expand Up @@ -28,11 +28,13 @@
# after downloading and importing it.
# use forward slashes instead of back slashes

setwd( "C:/My Directory/ARF/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/ARF/" )
# ..in order to set your current working directory


# remove the # in order to run this install.packages line only once
# install.packages( c( 'SAScii' , 'descr' , 'RSQLite' ) )
# install.packages( c( 'SAScii' , 'descr' , 'RSQLite' , 'downloader' ) )



Expand All @@ -44,29 +46,16 @@ setwd( "C:/My Directory/ARF/" )
# # # # # # # # #


#######################################################
# function to download scripts directly from github.com
# http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)

# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
}
#######################################################

# load the read.SAScii.sqlite function (a variant of read.SAScii that creates a database directly)
source_https( "https://raw.github.com/ajdamico/usgsd/master/SQLite/read.SAScii.sqlite.R" )


# load necessary libraries
require(RSQLite) # load RSQLite package (creates database files in R)
require(SAScii) # load the SAScii package (imports ascii data with a SAS script)
require(descr) # load the descr package (converts fixed-width files to delimited files)
require(foreign) # load foreign package (converts data files into R)
require(downloader) # downloads and then runs the source() function on scripts from github


# load the read.SAScii.sqlite function (a variant of read.SAScii that creates a database directly)
source_url( "https://raw.github.com/ajdamico/usgsd/master/SQLite/read.SAScii.sqlite.R" )


# create a temporary database file and another temporary file
Expand Down Expand Up @@ -140,7 +129,7 @@ gc()


# print a reminder: set the directory you just saved everything to as read-only!
winDialog( 'ok' , paste( "all done. you should set" , getwd() , "read-only so you don't accidentally alter these files." ) )
message( paste( "all done. you should set" , getwd() , "read-only so you don't accidentally alter these files." ) )

# for more details on how to work with data in r
# check out my two minute tutorial video site
Expand Down
Expand Up @@ -151,7 +151,7 @@ for ( zf in all.files ){


# print a reminder: set the directory you just saved everything to as read-only!
winDialog( 'ok' , paste( "all done. you should set" , getwd() , "read-only so you don't accidentally alter these files." ) )
message( paste( "all done. you should set" , getwd() , "read-only so you don't accidentally alter these files." ) )


# for more details on how to work with data in r
Expand Down
Expand Up @@ -36,10 +36,10 @@


# remove the # in order to run this install.packages line only once
# install.packages( c( "RCurl" , "R.utils" ) )
# install.packages( c( "downloader" , "R.utils" ) )


require(RCurl) # load RCurl package (downloads files from the web)
require(downloader) # downloads and then runs the source() function on scripts from github
require(R.utils) # load the R.utils package (counts the number of lines in a file quickly)
require(RMonetDB) # load the RMonetDB package (connects r to a monet database)

Expand Down Expand Up @@ -67,24 +67,10 @@ setwd( "C:/My Directory/BSAPUF/" )
year <- 2008


#######################################################
# function to download scripts directly from github.com
# http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)

# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
}
#######################################################

# load the windows.monetdb.configuration() function,
# which allows the easy creation of an executable (.bat) file
# to run the monetdb server specific to this data
source_https( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/windows.monetdb.configuration.R" )
source_url( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/windows.monetdb.configuration.R" )


# create a folder "MonetDB" in your current working directory.
Expand Down Expand Up @@ -385,9 +371,9 @@ db <- dbConnect( drv , monet.url , user = "monetdb" , password = "monetdb" )


# unlike most post-importation scripts, the monetdb directory cannot be set to read-only #
winDialog( 'ok' , paste( "all done. DO NOT set" , getwd() , "read-only or subsequent scripts will not work." ) )
message( paste( "all done. DO NOT set" , getwd() , "read-only or subsequent scripts will not work." ) )

winDialog( 'ok' , "got that? monetdb directories should not be set read-only." )
message( "got that? monetdb directories should not be set read-only." )
# don't worry, you won't update any of these tables so long as you exclusively stick with the dbGetQuery() function
# instead of the dbSendUpdate() function (you'll see examples in the analysis scripts)

Expand Down
Expand Up @@ -52,8 +52,9 @@


require(sqlsurvey) # load sqlsurvey package (analyzes large complex design surveys)
require(RMonetDB) # load the RMonetDB package (connects r to a monet database)
require(RMonetDB) # load the RMonetDB package (connects r to a monet database)
require(foreign) # load foreign package (converts data files into R)
require(downloader) # downloads and then runs the source() function on scripts from github

# set your BRFSS data directory
# after downloading and importing
Expand All @@ -65,29 +66,15 @@ setwd( "C:/My Directory/BRFSS/" )



#######################################################
# function to download scripts directly from github.com
# http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)

# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
}
#######################################################

# load the windows.monetdb.configuration() function,
# which allows the easy creation of an executable (.bat) file
# to run the monetdb server specific to this data
source_https( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/windows.monetdb.configuration.R" )
source_url( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/windows.monetdb.configuration.R" )

# load the read.SAScii.monetdb() function,
# which imports ASCII (fixed-width) data files directly into a monet database
# using only a SAS importation script
source_https( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/read.SAScii.monetdb.R" )
source_url( "https://raw.github.com/ajdamico/usgsd/master/MonetDB/read.SAScii.monetdb.R" )


# create a folder "MonetDB" in your current working directory.
Expand Down Expand Up @@ -540,9 +527,9 @@ db <- dbConnect( drv , monet.url , user = "monetdb" , password = "monetdb" )


# unlike most post-importation scripts, the monetdb directory cannot be set to read-only #
winDialog( 'ok' , paste( "all done. DO NOT set" , getwd() , "read-only or subsequent scripts will not work." ) )
message( paste( "all done. DO NOT set" , getwd() , "read-only or subsequent scripts will not work." ) )

winDialog( 'ok' , "got that? monetdb directories should not be set read-only." )
message( "got that? monetdb directories should not be set read-only." )


# for more details on how to work with data in r
Expand Down
Binary file not shown.
Expand Up @@ -28,7 +28,10 @@
# after downloading and importing it.
# use forward slashes instead of back slashes

setwd( "C:/My Directory/CES/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/CES/" )
# ..in order to set your current working directory



require(foreign) # load foreign package (converts data files into R)
Expand Down Expand Up @@ -166,7 +169,7 @@ for ( year in years.to.download ){


# print a reminder: set the directory you just saved everything to as read-only!
winDialog( 'ok' , paste( "all done. you should set" , getwd() , "read-only so you don't accidentally alter these files." ) )
message( paste( "all done. you should set" , getwd() , "read-only so you don't accidentally alter these files." ) )

# for more details on how to work with data in r
# check out my two minute tutorial video site
Expand Down
26 changes: 7 additions & 19 deletions Consumer Expenditure Survey/2011 fmly intrvw - analysis examples.R
Expand Up @@ -46,7 +46,10 @@
# then the working directory should be set to "C:/My Directory/CES/"
# use forward slashes instead of back slashes

setwd( "C:/My Directory/CES/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/CES/" )
# ..in order to set your current working directory



# turn off scientific notation in most output
Expand All @@ -55,34 +58,19 @@ options( scipen = 20 )


# remove the # in order to run this install.packages line only once
# install.packages( c( "RSQLite" , "mitools" , "stringr" , "plyr" , "survey" , "RCurl" ) )
# install.packages( c( "RSQLite" , "mitools" , "stringr" , "plyr" , "survey" , "downloader" ) )


require(RSQLite) # load RSQLite package (creates database files in R)
require(mitools) # allows analysis of multiply-imputed survey data
require(stringr) # load stringr package (manipulates character strings easily)
require(plyr) # contains the rbind.fill() function, which stacks two data frames even if they don't contain the same columns. the rbind() function does not do this
require(survey) # load survey package (analyzes complex design surveys)
require(RCurl) # load RCurl package (downloads files from the web)


#######################################################
# function to download scripts directly from github.com
# http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)

# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
}
#######################################################
require(downloader) # downloads and then runs the source() function on scripts from github


# load two svyttest functions (one to conduct a df-adjusted t-test and one to conduct a multiply-imputed t-test)
source_https( "https://raw.github.com/ajdamico/usgsd/master/Consumer%20Expenditure%20Survey/ces.svyttest.R" )
source_url( "https://raw.github.com/ajdamico/usgsd/master/Consumer%20Expenditure%20Survey/ces.svyttest.R" )
# now that these two functions have been loaded into r, you can view their source code by uncommenting the two lines below
# svyttest.df
# svyttest.mi
Expand Down
Expand Up @@ -48,7 +48,9 @@
# then the working directory should be set to "C:/My Directory/CES/"
# use forward slashes instead of back slashes

setwd( "C:/My Directory/CES/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/CES/" )
# ..in order to set your current working directory


# turn off scientific notation in most output
Expand Down
Expand Up @@ -28,11 +28,14 @@
# after downloading and importing them.
# use forward slashes instead of back slashes

setwd( "C:/My Directory/CPS/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/CPS/" )
# ..in order to set your current working directory



# remove the # in order to run this install.packages line only once
# install.packages( c( "survey" , "RSQLite" , "SAScii" , "descr" , "RCurl" ) )
# install.packages( c( "survey" , "RSQLite" , "SAScii" , "descr" , "downloader" ) )


# define which years to download #
Expand Down Expand Up @@ -61,30 +64,16 @@ cps.dbname <- "cps.asec.db"
# if the cps database file already exists in the current working directory, print a warning
if ( file.exists( paste( getwd() , cps.dbname , sep = "/" ) ) ) warning( "the database file already exists in your working directory.\nyou might encounter an error if you are running the same year as before or did not allow the program to complete.\ntry changing the cps.dbname in the settings above." )

#######################################################
# function to download scripts directly from github.com
# http://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)

# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
}
#######################################################


require(RSQLite) # load RSQLite package (creates database files in R)
require(survey) # load survey package (analyzes complex design surveys)
require(SAScii) # load the SAScii package (imports ascii data with a SAS script)
require(descr) # load the descr package (converts fixed-width files to delimited files)
require(RCurl) # load RCurl package (downloads files from the web)
require(downloader) # downloads and then runs the source() function on scripts from github


# load the read.SAScii.sqlite function (a variant of read.SAScii that creates a database directly)
source_https( "https://raw.github.com/ajdamico/usgsd/master/SQLite/read.SAScii.sqlite.R" )
source_url( "https://raw.github.com/ajdamico/usgsd/master/SQLite/read.SAScii.sqlite.R" )


# set R to produce conservative standard errors instead of crashing
Expand Down Expand Up @@ -419,7 +408,7 @@ for ( year in cps.years.to.download ){


# print a reminder: set the directory you just saved everything to as read-only!
winDialog( 'ok' , paste0( "all done. you should set the file " , file.path( getwd() , cps.dbname ) , " read-only so you don't accidentally alter these tables." ) )
message( paste0( "all done. you should set the file " , file.path( getwd() , cps.dbname ) , " read-only so you don't accidentally alter these tables." ) )


# for more details on how to work with data in r
Expand Down
5 changes: 4 additions & 1 deletion Current Population Survey/2012 asec - analysis examples.R
Expand Up @@ -45,7 +45,10 @@
# after running the program described above
# use forward slashes instead of back slashes

setwd( "C:/My Directory/CPS/" )
# uncomment this line by removing the `#` at the front..
# setwd( "C:/My Directory/CPS/" )
# ..in order to set your current working directory



# remove the # in order to run this install.packages line only once
Expand Down

0 comments on commit d77350d

Please sign in to comment.