Skip to content

Commit

Permalink
Add symlinks to C++ source and a default .Rproj (grf-labs#440)
Browse files Browse the repository at this point in the history
Instead of copying files over, symlinks in `grf/src` now point to the
Rcpp bindings (`grf/bindings`) and core C++ (`core/src`). This allows
RStudio's Build menu (accompanying .Rproj file) to work, allowing for
quicker conditional compilation when working on both R and C++ changes.
  • Loading branch information
erikcs authored Jul 19, 2019
1 parent fd802b8 commit 4444583
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.DS_Store
.Rproj.user
26 changes: 24 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@

In addition to providing out-of-the-box forests for quantile regression and instrumental variables, grf provides a framework for creating forests tailored to new statistical tasks. Certain components around splitting and prediction can be swapped out, within the general infrastructure for growing and predicting on trees.

### Working with the code
## Contributing

The core forest implementation is written in C++, with an R interface powered by Rcpp. We recommend using a full-powered C++ IDE such as CLion, Xcode, or Visual Studio when working with the core code. To build the R package from source, cd into `r-package` and run the `build_package.R` script. Code style consistency is checked with the [lintr](https://github.com/jimhester/lintr) package, and in RStudio you can make sure the code is consistent with the R standard by clicking _Addins->Style_.
This repository follows the standard open source protocol and setup with git where there is an abundance of existing resources to get up to speed (see for example the
contributing guidelines for well known packages in other languages, like Scikit-learn, Scipy, and pandas)

Condensed greatly, the workflow is to fork this repository, check out a branch, commit your changes (forming an ideally legible commit history),
then submitting a pull request explaining your contribution, ideally referring to the issue you created, or the issue you chose to work on.

## Working with the code

The core forest implementation is written in C++, with an R interface powered by Rcpp. We recommend using a full-powered C++ IDE such as CLion, Xcode, or Visual Studio when working with the core code.

## R package

To build the R package from source, cd into `r-package` and run `build_package.R`. Required development dependencies are listed there
(note: it is recommended to install the latest [lintr](https://github.com/jimhester/lintr) package with `devtools::install_github("jimhester/lintr")`). This mimics the tests run when submitting a pull request.

An alternative development workflow is to use the accompanying grf.Rproj and build and test the package with RStudio's build menu, which can be convenient
for quickly iterating C++/R code changes.

### Note for Windows users:

Symlinks in the src directory point to the core C++ and R bindings. On Windows one has to clone this repository with symlinks enabled: `git clone -c core.symlinks=true https://github.com/grf-labs/grf.git` (this command needs to be run as an administrator: right click _Command Prompt -> Run as administrator_). Caveat: the above RStudio workflow is not tested on Windows.

## Core C++

### Code structure

Expand Down
4 changes: 2 additions & 2 deletions r-package/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
# clion files
.idea/

# copied src files
grf/src/*
# Generated files
grf/src/RcppExports.cpp

# documentation by roxygen
*.Rd
15 changes: 3 additions & 12 deletions r-package/build_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ library(roxygen2)
library(lintr)

package.name <- "grf"
package.src <- "grf/src"

# Check code style consistency
linters <- with_defaults(
Expand All @@ -36,21 +35,13 @@ if (!is.na(args[1]) && args[1] == "--as-cran") {
write_union("grf/.Rbuildignore", "^tests/testthat/test_((?!cran).).*")
}

# Copy Rcpp bindings and C++ source into the package src directory. Note that we
# don't copy in third_party/Eigen, because for the R package build we provide
# access to the library through RcppEigen.
unlink(package.src, recursive = TRUE)
dir.create(package.src)

binding.files <- list.files("grf/bindings", full.names = TRUE)
file.copy(binding.files, package.src, recursive = FALSE)
file.copy("../core/src", package.src, recursive = TRUE)
file.copy("../core/third_party/optional", package.src, recursive = TRUE)

# Auto-generate documentation files
roxygen2::roxygenise(package.name)

# Run Rcpp and build the package.
# Symlinks in `grf/src` point to the Rcpp bindings (`grf/bindings`) and core C++ (`core/src`).
# Note: we don't link in third_party/Eigen, because for the R package build we provide
# access to the library through RcppEigen.
compileAttributes(package.name)
clean_dll(package.name)
build(package.name)
Expand Down
21 changes: 21 additions & 0 deletions r-package/grf/grf.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
1 change: 1 addition & 0 deletions r-package/grf/src/AnalysisToolsBindings.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/CausalForestBindings.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/CustomForestBindings.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/InstrumentalForestBindings.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/Makevars
1 change: 1 addition & 0 deletions r-package/grf/src/QuantileForestBindings.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/RcppUtilities.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/RcppUtilities.h
1 change: 1 addition & 0 deletions r-package/grf/src/RegressionForestBindings.cpp
1 change: 1 addition & 0 deletions r-package/grf/src/optional
1 change: 1 addition & 0 deletions r-package/grf/src/src

0 comments on commit 4444583

Please sign in to comment.