[R] reading in stata file with read.dta works in R x64 3.0.1 and crashes R x64 3.0.2

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Nov 7 16:41:00 CET 2013


See the posting guide: your version of 'foreign' is not current: 
http://cran.r-project.org/web/packages/foreign/index.html .

Please update your packages and try again.  (This looks very like a bug 
in recently contributed code that has already been fixed.)

On 07/11/2013 13:40, Anthony Damico wrote:
> this file
>
>
> http://www.electionstudies.org/studypages/data/anes_mergedfile_1992to1997/anes_mergedfile_1992to1997_dta.zip
>
> can be downloaded after free registration on this page
>
>      http://electionstudies.org/studypages/download/registration_form.php
>
>
> imports properly in windows R x64 3.0.1 but causes R x64 3.0.2 to crash
>
>
> the crash occurs at the line
>
> rval <- .External(do_readStata, file)
>
>
> at the bottom of this e-mail, i have included code that will reproduce the
> problem exactly in 3.0.2 but not 3.0.1
>
>
> and if i don't load the memisc and Hmisc packages, i get an error instead
> of a crash..
>
>
>> x <- read.dta( fp , convert.factors = FALSE )
> Error in read.dta(fp, convert.factors = FALSE) :
>    Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL'
>
>
> ..but if i load both (as shown in the script below), R just dies.
>
>
> =================
>
>
> sessionInfo for 3.0.1 (the version that works)
>
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252    LC_MONETARY=English_United States.1252
> LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] grid      splines   stats     graphics  grDevices utils     datasets
> methods   base
>
> other attached packages:
> [1] memisc_0.96-6   MASS_7.3-26     lattice_0.20-15 Hmisc_3.12-2
> Formula_1.1-1   survival_2.37-4 httr_0.2        stringr_0.6.2
> foreign_0.8-53
>
> loaded via a namespace (and not attached):
> [1] cluster_1.14.4 digest_0.6.3   RCurl_1.95-4.1 rpart_4.1-1
> tools_3.0.1
>
>
> =================
>
> sessionInfo in 3.0.2 right before the crash --
>
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] grid      splines   stats     graphics  grDevices utils     datasets
> [8] methods   base
>
> other attached packages:
> [1] memisc_0.96-6   MASS_7.3-29     lattice_0.20-23 Hmisc_3.12-2
> [5] Formula_1.1-1   survival_2.37-4 httr_0.2        stringr_0.6.2
> [9] foreign_0.8-55
>
> loaded via a namespace (and not attached):
> [1] cluster_1.14.4 digest_0.6.3   RCurl_1.95-4.1 rpart_4.1-3
> tools_3.0.2
>
>
>
>
> =================
>
>
> # code that works in 3.0.1 and crashes in 3.0.2 --
>
>
> setwd( "C:/my directory/anes")
> your.username <- "email at address.com"
> your.password <- "your.password"
>
>
>
>
> require(foreign)     # load foreign package (converts data files into R)
> require(stringr)    # load stringr package (manipulates character strings
> easily)
> require(httr)        # load httr package (downloads files from the web,
> with SSL and cookies)
> require(Hmisc)         # load Hmisc package (loads spss.get function)
> require(memisc)        # load memisc package (loads spss portable table
> import functions)
>
> # construct a list containing the pre-specified login information
> values <-
>      list(
>          "email" = your.username ,
>          "pass" = your.password
>      )
>
> # contact the anes website to log in
> POST( "http://www.electionstudies.org/studypages/download/login-process.php"
> , body = values )
>
> # download the `all_datasets` page to figure out what needs to be downloaded
> z <- GET( "
> http://www.electionstudies.org/studypages/download/datacenter_all_datasets.php"
> )
>
> # create a temporary file and a temporary directory
> tf <- tempfile() ; td <- tempdir()
>
> # download the damn file
> z <- GET( "
> http://www.electionstudies.org/studypages/data/anes_mergedfile_1992to1997/anes_mergedfile_1992to1997_dta.zip"
> )
>
> # save the result to a temporary file on the local disk
> writeBin( z$content , tf )
>
> # unzip that temporary file to an equally-temporary directory
> z <- unzip( tf , exdir = td )
>
> # find which one it is from among everything zipped up together..
> fp <- z[ grep( 'dta' , z ) ]
>
> # ..import that puppy
> x <- read.dta( fp , convert.factors = FALSE )
> # crash.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list