rgeoda dev notes (1)
rgeoda dev notes (1)
Couple of things for v0.0.5:
-
Get it ready for CRAN
1.1. random number generator: replace srand() and rand()
1.2. using Rcpp instead of SWIG R wrappers (this might take a long time)
1.3. update makefile
Rstudio notes:
The following dependencies are required:
- BH
- sp
- sf
- wkb
- rmarkdown
- knitr
- roxygen2
Rcpp notes:
- To expose all functions in different Rcpp files
Create a R script file e.g. init.R. Add the following lines, e.g.
#' @importFrom Rcpp evalCpp
#' @useDynLib rgeoda
NULL
Then, add it in Collate in the file DESCRIPTION
, e.g.
Collate:
init.R
Roxygen2 will use it to automatically generate the NAMESPACE
file using the content in init.R, e.g.:
# Generated by roxygen2: do not edit by hand
export(geoda_open)
importFrom(Rcpp,evalCpp)
useDynLib(rgeoda)
- The design of rgeoda and the bridge to C++ classes and functions in libgeoda
For example, wrapping the GeoDa C++ class for rgeoda
First, rcpp_geoda.cpp
is created to expose GeoDa C++ class. Rcpp will auto-generate a file RcppExports.cpp
and furthur provide C-style static interfaces, which can be called in R using another automatically generated file RcppExports.R
.
Second, rgeoda.R
is created to provide a R S4 class p_GeoDa
to manually wrap the GeoDa C++ class, which is now available in RcppExports.R
. NOTE: the constructors are complex to using ‘RcppModule’ to wrap the whole C++ class.
Last, at this stage, users can use rgeoda.R
and p_GeoDa
class directly. But, for a R-friendly purpose, I added another R S4 class geoda
in file read_geoda.R
to decorate the p_GeoDa
class.
In summary, the logic of wrapping a C++ class can be described as:
rcpp_xxx.cpp (expose GeoDa C++ class using Rcpp)
|
|
\|/
rxxx.R (Wrap above C++ class via RcppExports.R)
|
|
\|/
(decorate).R (optional) (Wrap above R class for R-friendly purpose)
Check Warnings
-
checking whether package ‘rgeoda’ can be installed … WARNING
-
GNU extensions in Makefile
* checking for GNU extensions in Makefiles ... WARNING
Found the following file(s) containing GNU extensions:
src/Makevars
Portable Makefiles do not use GNU extensions such as +=, :=, $(shell),
$(wildcard), ifeq ... endif, .NOTPARALLEL See section ‘Writing portable
packages’ in the ‘Writing R Extensions’ manual.
Fix it by listing the source files instead.
* checking S3 generic/method consistency ... WARNING
as.data.frame:
function(x, row.names, optional, ...)
as.data.frame.geoda:
function(gda_obj)
Fixed by using exact same parameters of as.data() function.
* checking compiled code ... NOTE
File ‘rgeoda/libs/rgeoda.so’:
Found ‘_rand’, possibly from ‘rand’ (C)
Objects: ‘./libgeoda_src/clustering/cluster.o’,
‘./libgeoda_src/clustering/maxp.o’,
‘./libgeoda_src/clustering/mds.o’, ‘./libgeoda_src/GenUtils.o’
Found ‘_srand’, possibly from ‘srand’ (C)
Objects: ‘./libgeoda_src/clustering/cluster.o’,
‘./libgeoda_src/clustering/maxp.o’,
‘./libgeoda_src/clustering/mds.o’, ‘./libgeoda_src/GenUtils.o’
Compiled code should not call entry points which might terminate R nor
write to stdout/stderr instead of to the console, nor use Fortran I/O
nor system RNGs.
Fixed by using xorshift+ rng.