[R] Understanding contents of packages

Berend Hasselman bhh at xs4all.nl
Thu Apr 11 21:11:03 CEST 2013

On 11-04-2013, at 20:34, Fisher Dennis <fisher at plessthan.com> wrote:

> Colleagues
> During the transition to R3.0.0 (OS X), one of the packages that I used -- SASxport -- did not work until I used the "type=source" option in install.packages.   

See below. There is a binary version available.

> This led to an adventure:
> 	1.  I downloaded the package source:		SASxport_1.2.4.tar.gz
> 	2.  in the SASxport/R folder, I found all the functions that are part of the package.
> I became interested in whether I could "source" these functions directly into R and re-create the functionality of the package without installing/"require"ing the package.  
> This started with some success until I encountered one problem that I could not overcome.  
> When I executed the function write.xport, I received the following error message:
> 	Error in .C("fill_file_header", cDate = xport.dateFMT(cDate), mDate = xport.dateFMT(mDate), : 
>          C symbol name "fill_file_header" not in load table
> This appears to be coming from the following line of code in write.xport:
> 	out(xport.file.header( cDate = cDate, sasVer = sasVer, osType = osType))
> The problem appears to be in
> 	xport.file.header
> for which the entire code is:
> xport.file.header <-
>  function(cDate=Sys.time(), mDate=cDate, sasVer="7.00", osType="Unknown" )
>  {
>    .C("fill_file_header",
>       cDate = xport.dateFMT(cDate),           # Creation date
>       mDate = xport.dateFMT(mDate),           # Modification date
>       sasVer = toupper(as.character(sasVer)), # SAS version number
>       osType = as.character(osType) # Operating System (can include lowercase)
>       )
>    .Call("getRawBuffer", PACKAGE="SASxport")
>  }
> Of note, I commented out the line:
> 	.Call("getRawBuffer", PACKAGE="SASxport")
> and the same error occurred (I did not expect this is solve the problem).
> I then looked in SASxport/src and found three files (which appear to be coded in C):
> 	init.c
> 	writeSAS.c
> 	writeSAS.h
> that refer to "fill_file_header"
> I suspect that these files need to be accessed in some manner in order for xport.file.header and other functions to work correctly.  
> The question is how do I access these files:
> 	Do I "source" them in some manner?  
> 	Put them in a particular location where they are sourced automatically?  
> 	I tried dyn.load but that does not appear to be the correct approach.

These files are part of the package; packages have a strict organization of files.  The files you are referring to are C files and need to be compiled.
And that implies you will need to get hold of the appropriate compiler tools.

> Any help would be greatly appreciated.

The exercise is quite futile.
You really need to read the Writing R Extensions manual.

There is a binary version of this package available on CRAN, which you can install using R.app.
So you don't need to do what you are doing.


More information about the R-help mailing list