IDE / setup for package development with C++ code integrated
Pergunta
I'm trying to get a grip on C++/Rcpp as an extension to R for heavy computational tasks. Ultimately, these C++ libs should be integrated in a package, and therefor I'm looking for a setup / combination of tools / IDE that I would need to work easily. I know much is taste dependent, but still it would be nice to know my options before choosing.
So : when you develop R packages with C++ libs, what is the setup you work with?
- do you use the same editor / IDE for R and C++ and which one (or which ones) ?
- are there extra tools (apart from Rtools) that are important to get ?
- are there tweaks in the general setup that are important to know or speed up the process considerably?
Sorry if this question has been asked before. I found a list of all editors for R, but nothing specifically directed towards developing of packages including C++ code. Any hints or tips are really appreciated.
Edit : platform is Windows, but I can move to Linux without problems (dual boot, only thing keeping me from using ubuntu is the lack of a decent driver for my old card/old screen combination)
Solução
Eclipse + statet if you want to join in us in the modern world :)
Outras dicas
I'm of course fully in favour of more Rcpp work :)
As for your questions, and in order:
- same editor (Emacs) which makes for nice consistency on either platform I use (mostly Linux, occassionally Windows); for the record I have also spoke out in favour of the
qtcreator
IDE which is pretty nice on Linux and Windows (but doesn't do R). - no, on Linux it all comes ready made (and yes, on Windows you do need Rtools) ...
- not really -- you probably already know about inline which is good for testing R/C++ code snippets.
Edit: So in a way, this is really no different from normal R / C / C++ / Fortran development. And in that case I usually refer to R FAQ Section 6 which is devoted entirely to R and Emacs :) With that said, setting Emacs up for C++ work is not obvious and there are a number of questions and posts here. I do not use any particular class browser but there are some, as well as approaches to auto-completion of types etc.
You will want an editor that can handle multiple languages, R, C+, maybe Makefiles, etc. Since you mention Rtools it sounds like you are on Windows. I would suggest Notepad++ it handles R, C++, and a whole lot of other languages. Plus you can setup custom command through NppExec to build the package more easily. I have developed a few packages that make heavy use of C/C++ using Notepad++.
I just wrote a cmake script to generate Eclipse CDT project for developing Rcpp package.
Moreover, cmake might be able to generate CodeBlocks or KDevelop3 projects, but I have not checked these features, yet.
Environment
- CMake >= 2.8.7
- Eclipse >= 3.7
- Eclipse CDT >= 1.4.2
- R >= 2.15
- Rcpp >= 0.10
Configuration
Download FindLibR.cmake from github provided by Rstudio
Generate Rcpp package, for example
library(Rcpp) Rcpp.package.skeleton("RcppPackage")
Put the following script (or download it from gist), named CMakeLists.txt, in the generated folder such as
RcppPackage
in the previous example.cmake_minimum_required(VERSION 2.8) project(RcppPackage) find_package(LibR) if(${LIBR_FOUND}) else() message(FATAL_ERROR "No R...") endif() message(STATUS ${CMAKE_SOURCE_DIR}) execute_process( COMMAND ${LIBR_EXECUTABLE} "--slave" "-e" "stopifnot(require('Rcpp'));cat(Rcpp:::Rcpp.system.file('include'))" OUTPUT_VARIABLE LIBRCPP_INCLUDE_DIRS ) include_directories(BEFORE ${LIBR_INCLUDE_DIRS}) message(STATUS ${LIBR_INCLUDE_DIRS}) include_directories(BEFORE ${LIBRCPP_INCLUDE_DIRS}) message(STATUS ${LIBRCPP_INCLUDE_DIRS}) add_custom_target(RcppPackage ALL COMMAND find ${CMAKE_SOURCE_DIR} -name "*.o" -exec rm "{}" "\;" COMMAND find ${CMAKE_SOURCE_DIR} -name "*.so" -exec rm "{}" "\;" COMMAND ${LIBR_EXECUTABLE} "--slave" "-e" "\"stopifnot(require(roxygen2));roxygenize('${CMAKE_SOURCE_DIR}',roclets=c('rd','collate','namespace'))\"" COMMAND ${LIBR_EXECUTABLE} CMD INSTALL "${CMAKE_SOURCE_DIR}")
Customize
roxygenize
andR CMD INSTALL
in CMakeLists.txtGenerate project with cmake
mkdir build # don't create subdirectory of RcppPackage cd build cmake -G "Eclipse CDT4 - Unix Makefiles" <path to RcppPackage> -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE
Open eclipse and import project from
build
(See cmake-eclipse-cdt for example). After indexing, enjoy several convenient features provided by Eclipse CDT such as tracing and autocomplete.You can build the project which will be converted to
R CMD INSTALL
or anything in the CMakeLists.txt.