From simon.urbanek at r-project.org  Mon Sep  9 15:26:34 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Mon, 9 Sep 2013 09:26:34 -0400
Subject: [Rd] Package installation and path.package
In-Reply-To: <79265780-D119-450A-93F9-D5BA2A81C9B1@uni-bonn.de>
References: <79265780-D119-450A-93F9-D5BA2A81C9B1@uni-bonn.de>
Message-ID: <D2208CD6-8CA6-4A21-A112-9CE4E3BA1587@r-project.org>


On Sep 9, 2013, at 4:22 AM, Simon Zehnder wrote:

> Dear R-Devels,
> 
> I am writing right now my own package that makes use of 'tempfile' and there within with 'path.package'. When I install it, I get the error: Error in path.package("mypackage") : none of the packages are loaded. Here is the code, I use in my package:
> 
> 
> ".defaultDBPath"    <- function() 
> {
>    db.path <- tempfile(pattern     = "mmstructDB", 
>                        tmpdir      = file.path(path.package("mmstruct"),
>                                                "data", "databases"),
>                        fileext     = ".db")
>    return(db.path)
> }
> 
> .mmstructBASE <- setClass("mmstructBASE",
>                          		    representation("VIRTUAL",
>                                                                    dbName     = "character",
>                                                                    dbTable    = "character"),
>                                            prototype(dbName      = character(),
>                                                            dbTable     = character()
> 							    )
> )
> 
> .mmstructDB <- setClass("mmstructDB",                        
>                        representation("VIRTUAL",
>                                       conn = "SQLiteConnection"),
>                        contains = c("mmstructBASE"),
>                        prototype(conn  = dbConnect(dbDriver("SQLite"), .defaultDBPath()))
> )
> 
> I understand the error, but I would like to have a workaround. How can I give the path to the package I am actually installing without getting this error? 
> 

That path to your package is dynamic - in general it will not be know when creating the lazy-load DB, so you really want to put that code in .onLoad() where the path is known.

Cheers,
Simon


> 
> Best
> 
> Simon
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 



[Rd] Package installation and path.package
Simon Urbanek