[R-pkg-devel] Working with connections

Hadley Wickham h.wickham at gmail.com
Sun Aug 9 16:22:22 CEST 2015


Also it's a little strange to put an RDS file _inside_ a gz, since
normally the compression is done internally.

And are you sure you should be exposing this data via a function,
rather than using the regular package data mechanism?

Hadley

On Sun, Aug 9, 2015 at 7:04 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> On Sun, Aug 9, 2015 at 8:59 AM, Glenn Schultz <glennmschultz at me.com> wrote:
>> Hi All,
>>
>> I use connections to open and close data folders needed by my package.
>> After each function closes I get the following warnings (depending on the
>> connection that has been opened).
>>
>> 10: closing unused connection 3
>> (/Library/Frameworks/R.framework/Versions/3.2/Resources/library/BondLab/BondData/bondlabMBS4.rds)
>>
>> Below is the connection function that is related to the above warning:
>>
>> #------------------------------------------------------------------------------------
>>   #' A connection function to BondData calling MBS cusps
>>   #'
>>   #' Opens a connection to the BondData folder to call MBS cusip data
>>   #' @param MBS.id A character string the MBS.id or cusip number current
>> MBS.id is supported
>>   #' @export
>>   MBS <- function(MBS.id = "character"){
>>                   MBS.Conn <- gzfile(description = paste(system.file(package
>> = "BondLab"),
>>                               "/BondData/", MBS.id, ".rds", sep = ""), open
>> = "rb")
>>                   MBS <- readRDS(MBS.Conn)
>>                   return(MBS)
>>                   close.connection(MBS.Conn)
>>                   }
>>
>> I have googled this warning and it seems to be triggered when a function
>> terminates and the connection is open.  But, I think the connection function
>> closes the connection once the object is returned.  What am I doing wrong?
>>
> Your call to return() exits the function, so the close.connection()
> call is never evaluated.  Considering using on.exit() to close the
> connection, since it will close the connection regardless of how the
> function exits (e.g. because of an error).
>
>> -Glenn
>> ______________________________________________
>> R-package-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
>
>
> --
> Joshua Ulrich  |  about.me/joshuaulrich
> FOSS Trading  |  www.fosstrading.com
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



-- 
http://had.co.nz/



More information about the R-package-devel mailing list