1

I recently rewrote a package to use the new(er) R reference class objects. I've exported the three classes using export() in the NAMESPACE file so as far as I'm aware that should work. However when I test build the package I get an error at lazy loading stage:

** preparing package for lazy loading
Error in file(con, "rb") : invalid 'description' argument
ERROR: lazy loading failed for package ‘PACKAGE_NAME_HERE’
* removing ‘/Library/Frameworks/R.framework/Versions/3.0/Resources/library/PACKAGE_NAME_HERE’

I'm not sure what the problem is here. I don't know if it's relevant but the reference classes do store data on files in the tmp directory by having some fields set as accessor functions - I don't know if that's what s being complained about here when it says (con, "rb") which I guess is some connection thing. Does anybody have any ideas or advice for making sure reference classes get exported properly? My namespace is currently simple -

export(Main)
export(Mainseq)
export(Maintriplet)

Which are the three reference classes I exported by using @export tags in roxygen2. What is it I'm doing (or not doing) that is throwing the lazy load error?

(ASIDE - I have no compiled code - all R, although the reference class methods do call some internal functions that are not exported, but these are supposed to be internal so I don't think I need to export them.

Thanks, Ben.

EDIT:

My description file is as follows:

Package: HybRIDS
Type: Package
Title: Quick detection and dating of Recombinant Regions in DNA sequence data.
Version: 1.0
Date: 2013-03-13
Author: Ben J. Ward
Maintainer: Ben J. Ward <b.ward@uea.ac.uk>
Description: A simple R package for the quick detection and dating of Recombinant Regions in DNA sequence data.
License: GPL-2
Depends: ggplot2,grid,gridExtra,png,ape

I can't see what is wrong with this - the Depends are correct.

EDIT:

I've eliminated the first error with the description but I'm still getting the con error. I think it's because the Mainseq class (which is nested in class Main) has some fields:

FullSequenceFile = "character",

                              FullSequence = function( value ) {
                                if( missing( value ) ){
                                  as.character( read.dna( file = FullSequenceFile, format = "fasta", as.matrix = TRUE ) )
                                } else {
                                  write.dna( value, file = FullSequenceFile, format = "fasta" )
                                }
                              },

                              InformativeSequenceFile = "character",

                              InformativeSequence = function( value ) {
                                if( missing( value ) ){
                                  as.character( read.dna( file = InformativeSequenceFile, format = "fasta", as.matrix = TRUE ) )
                                } else {
                                  write.dna( value, file = InformativeSequenceFile, format = "fasta" )
                                }
                              }

The idea being upon initialisation, the two character fields are filled with a path to a temp file in tmpdir, and when the variables are called or edited the files containing the variable data are read or written to. However it seems the variables are being accessed before this path is available because up package build the following happens:

** preparing package for lazy loading
Warning in file(con, "rb") :
  cannot open file '/var/folders/kp/clkqvqn9739ffw2755zjwy74_skf_z/T//RtmpLB8ESC/FullSequenceaba52ac591f3': No such file or directory
Error in file(con, "rb") : cannot open the connection
SJWard
  • 3,629
  • 5
  • 39
  • 54
  • Just tried it again but this time exporting the non-exported functions as docs say functions called from methods should be exported: export(autodetect.thresholds) export(col_deter) export(date.blocks) export(HybRIDS) export(HybRIDSseq) export(HybRIDStriplet) export(seq.similarity) export(vertbar_create) but alas I still get the error. – SJWard Sep 10 '13 at 16:04
  • I think you need to read the error message and look at your `DESCRIPTION`... – hadley Sep 10 '13 at 16:40
  • Updated the origional question with my DESCRIPTION file – SJWard Sep 10 '13 at 23:52
  • I've taken out all the files from my package and added each one and adding them to the namespace file for export one by one. I started with the "internal" functions and then the two reference classes that are part of the larger one. the package built right up until the final Reference class that contains the other two, at the inclusion of this file - which contains only code for that class, I get the error. Maybe I have to specify the order things are loaded? I can't see what's wrong with my description file above. – SJWard Sep 11 '13 at 00:23
  • So I've been commenting out code and found that the issue seems to be with that one of the fields of class Main, is the class Mainseq, and commenting this out seems to eliminate the issue, I'm wondering if there's some function in the Mainseq object which uses a con (it does read and write files in a accessor function to store data in tmp) and it is this which is messing things up. – SJWard Sep 11 '13 at 00:48
  • Ok I've found the issue in the troublesome class - I've updated the original question. – SJWard Sep 11 '13 at 00:56
  • Hi, if I change the class for the field in Main that contains Mainseq from "Mainseq" to "ANY" then the error goes away, I'm not sure why this is but I'm spitballing that if "Mainseq" is put as the class the access functions are called before the files are actually created by the user reading in sequence data when the Mainseq object is created. The design of my code so far work when sourcing in the files, but I suppose the order of sourcing and order of operations I then do on the objects I make eliminate the problem. – SJWard Sep 11 '13 at 01:15
  • Assuming that [this](https://github.com/Ward9250/HybRIDS) is your package, I don't get any of those warnings - https://gist.github.com/hadley/d97b573f5f041dd48d91. So you need to provide more input about what exactly you're doing. – hadley Sep 11 '13 at 02:07
  • Hi, that is the package, although it is the version without the reference classes (which were in devel and not master) although now that version w/o reference classes is now branch legacy, and both devel and main are the brances with reference classes (I merged them today but will double check). I have solved the error for now by in my changing a field of the HyBRIDS ref class 'DNA' from 'HybRIDSseq' to 'ANY', however I'm not sure that's really the right way of properly addressing the error. – SJWard Sep 12 '13 at 02:07

0 Answers0