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


On Sep 9, 2013, at 9:26 AM, Simon Urbanek wrote:

> 
> 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'.

BTW: if it's truly a temporary file, that that is a really bad idea - most users don't even have write-access to the library. That's why there is a separate facility for tempfiles, because you need something that the user has write-permissions for.


>> 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