Function/file names are hypothetical. Say I have written myfunction.R,
which calls myfunction.c via .C("myfunction", ...).
I've compiled successfully myfunction.c via R CMD SHLIB myfunction.c
in the terminal. Then, in the R console:
dyn.load("myfunction.so")
source("myfunction.R")
test <- myfunction() # works fine
So everything is in order, myfunction works perfectly.
Now I want to include myfunction() into a package called mypackage.
Here's what I did:
1) I've added PACKAGE = "mypackage" in the .C() line in myfunction.R.
2) I put myfunction.R into the R folder of mypackage
3) I put myfunction.c into the src folder of mypackage
4) I created myfunction.Rd into the man folder
I then build the package via R CMD build mypackage. All good. However,
when I run R CMD check mypackage, I get the following error (note that
I translated from french, might be a bit different in english):
Error in .C("myfunction", ...): C symbol name "myfunction" cannot be
found in the DLL for package "mypackage"
I would appreciate some help here. Please do not refer my to "Writing
R extensions" - if the answer's in there, I don't understand it.
Many thanks.
--
Etienne Lalibert?
================================
Rural Ecology Research Group
School of Forestry
University of Canterbury
Private Bag 4800
Christchurch 8140, New Zealand
Phone: +64 3 366 7001 ext. 8365
Fax: +64 3 364 2124
www.elaliberte.info
R CMD check: Error in .C
5 messages · Etienne Laliberté, Duncan Murdoch, Mathieu Ribatet +1 more
Etienne Lalibert? wrote:
Function/file names are hypothetical. Say I have written myfunction.R,
which calls myfunction.c via .C("myfunction", ...).
I've compiled successfully myfunction.c via R CMD SHLIB myfunction.c
in the terminal. Then, in the R console:
dyn.load("myfunction.so")
source("myfunction.R")
test <- myfunction() # works fine
So everything is in order, myfunction works perfectly.
Now I want to include myfunction() into a package called mypackage.
Here's what I did:
1) I've added PACKAGE = "mypackage" in the .C() line in myfunction.R.
2) I put myfunction.R into the R folder of mypackage
3) I put myfunction.c into the src folder of mypackage
4) I created myfunction.Rd into the man folder
I then build the package via R CMD build mypackage. All good. However,
when I run R CMD check mypackage, I get the following error (note that
I translated from french, might be a bit different in english):
Error in .C("myfunction", ...): C symbol name "myfunction" cannot be
found in the DLL for package "mypackage"
I would appreciate some help here. Please do not refer my to "Writing
R extensions" - if the answer's in there, I don't understand it.
What do you get from R CMD INSTALL mypackage? Duncan Murdoch
Many thanks. -- Etienne Lalibert? ================================ Rural Ecology Research Group School of Forestry University of Canterbury Private Bag 4800 Christchurch 8140, New Zealand Phone: +64 3 366 7001 ext. 8365 Fax: +64 3 364 2124 www.elaliberte.info
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Dear Etienne,
You probably want to create a zzz.R file in the /mypkg/R/ folder which
is just
.First.lib <- function(lib, pkg){
library.dynam("MyPkgName", package = pkg, lib.loc = lib)
return(invisible(0))
}
This would ensure that your shared library will be loaded.
Best,
Mathieu
Le lundi 26 octobre 2009 ? 03:58 +0100, Etienne Lalibert? a ?crit :
Function/file names are hypothetical. Say I have written myfunction.R,
which calls myfunction.c via .C("myfunction", ...).
I've compiled successfully myfunction.c via R CMD SHLIB myfunction.c
in the terminal. Then, in the R console:
dyn.load("myfunction.so")
source("myfunction.R")
test <- myfunction() # works fine
So everything is in order, myfunction works perfectly.
Now I want to include myfunction() into a package called mypackage.
Here's what I did:
1) I've added PACKAGE = "mypackage" in the .C() line in myfunction.R.
2) I put myfunction.R into the R folder of mypackage
3) I put myfunction.c into the src folder of mypackage
4) I created myfunction.Rd into the man folder
I then build the package via R CMD build mypackage. All good. However,
when I run R CMD check mypackage, I get the following error (note that
I translated from french, might be a bit different in english):
Error in .C("myfunction", ...): C symbol name "myfunction" cannot be
found in the DLL for package "mypackage"
I would appreciate some help here. Please do not refer my to "Writing
R extensions" - if the answer's in there, I don't understand it.
Many thanks.
--
Etienne Lalibert?
================================
Rural Ecology Research Group
School of Forestry
University of Canterbury
Private Bag 4800
Christchurch 8140, New Zealand
Phone: +64 3 366 7001 ext. 8365
Fax: +64 3 364 2124
www.elaliberte.info
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Institute of Mathematics Ecole Polytechnique F?d?rale de Lausanne STAT-IMA-FSB-EPFL, Station 8 CH-1015 Lausanne Switzerland http://stat.epfl.ch/ Tel: + 41 (0)21 693 7907
Many thanks Mathieu, following your answer I did a bit more focused
research and found out that because "mypackage" had a NAMESPACE, I had
to create the following zzz.R file instead:
.onLoad <-function (lib, pkg) {
library.dynam("mypackage", pkg, lib)
}
I then had a look in "Writing R extensions" to see if I had just
missed this precious info, but though they mention:
"If the ?src? subdirectory of an add-on package contains source
code with one of the extensions
listed above or a file ?Makevars? but not a file Makefile, R CMD
INSTALL creates a shared object
(for loading into R in the .First.lib or .onLoad function of the
package) using the R CMD
SHLIB mechanism. If file ?Makevars? exists it is read first, then the
system makefile and then
any personal ?Makevars? files."
To a novice like me, I really think this is not clear enough. It would
be nice if "Writing R extensions" was a bit more explicit about this
zzz.R solution.
Le 26 octobre 2009 23:44, Mathieu Ribatet <mathieu.ribatet at epfl.ch> a ?crit :
Dear Etienne,
You probably want to create a zzz.R file in the /mypkg/R/ folder which
is just
? ? ? ?.First.lib <- function(lib, pkg){
? ? ? ? ?library.dynam("MyPkgName", package = pkg, lib.loc = lib)
? ? ? ? ?return(invisible(0))
? ? ? ?}
This would ensure that your shared library will be loaded.
Best,
Mathieu
Le lundi 26 octobre 2009 ? 03:58 +0100, Etienne Lalibert? a ?crit :
Function/file names are hypothetical. Say I have written myfunction.R,
which calls myfunction.c via .C("myfunction", ...).
I've compiled successfully myfunction.c via R CMD SHLIB myfunction.c
in the terminal. Then, in the R console:
dyn.load("myfunction.so")
source("myfunction.R")
test <- myfunction() # works fine
So everything is in order, myfunction works perfectly.
Now I want to include myfunction() into a package called mypackage.
Here's what I did:
1) I've added PACKAGE = "mypackage" in the .C() line in myfunction.R.
2) I put myfunction.R into the R folder of mypackage
3) I put myfunction.c into the src folder of mypackage
4) I created myfunction.Rd into the man folder
I then build the package via R CMD build mypackage. All good. However,
when I run R CMD check mypackage, I get the following error (note that
I translated from french, might be a bit different in english):
Error in .C("myfunction", ...): C symbol name "myfunction" cannot be
found in the DLL for package "mypackage"
I would appreciate some help here. Please do not refer my to "Writing
R extensions" - if the answer's in there, I don't understand it.
Many thanks.
--
Etienne Lalibert?
================================
Rural Ecology Research Group
School of Forestry
University of Canterbury
Private Bag 4800
Christchurch 8140, New Zealand
Phone: +64 3 366 7001 ext. 8365
Fax: +64 3 364 2124
www.elaliberte.info
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
-- Institute of Mathematics Ecole Polytechnique F?d?rale de Lausanne STAT-IMA-FSB-EPFL, Station 8 CH-1015 Lausanne ? Switzerland http://stat.epfl.ch/ Tel: + 41 (0)21 693 7907
-- Etienne Lalibert? ================================ Rural Ecology Research Group School of Forestry University of Canterbury Private Bag 4800 Christchurch 8140, New Zealand Phone: +64 3 366 7001 ext. 8365 Fax: +64 3 364 2124 www.elaliberte.info
[ Note that this discussion really belongs to r-help, not r-devel, but a nyway.
On Tue, 27 Oct 2009 09:02:12 +1300, Etienne Lalibert? (EL) wrote:
> Many thanks Mathieu, following your answer I did a bit more focused
> research and found out that because "mypackage" had a NAMESPACE, I had
> to create the following zzz.R file instead:
> .onLoad <-function (lib, pkg) {
> library.dynam("mypackage", pkg, lib)
> }
If you have a namespace you only need a
useDynLib(mypackage)
in the NAMESPACE file, everything else is done automatically for you
(no need for the above zzz.R).
Best,
Fritz
----------------------------------------------------------------------- Prof. Dr. Friedrich Leisch Institut f?r Statistik Tel: (+49 89) 2180 3165 Ludwig-Maximilians-Universit?t Fax: (+49 89) 2180 5308 Ludwigstra?e 33 D-80539 M?nchen http://www.statistik.lmu.de/~leisch ----------------------------------------------------------------------- Journal Computational Statistics --- http://www.springer.com/180 M?nchner R Kurse --- http://www.statistik.lmu.de/R