Giter Site home page Giter Site logo

rtemplateproject's Introduction

Template R Project Structure

Do's and Dont's

Be stylish! Keep a consistent style to the code. Follow the tidyverse R style guide https://style.tidyverse.org/.

Initialize the project with a GIT repository Always initiate your project with at GIT repository, and use version control throughout.

And write sensible GIT commit messages to your future self Read this https://chris.beams.io/posts/git-commit/ :-)

Keep a tidy folder structure Use the following folder structure as a starting point

R Contains R source files. Why is it called R? Because devtools and R packages require this, so it's the most compatible naming convention.

config Contains all configuration data

data Contains all data used in the project

data/raw Contains raw input files as received

data/temp Contains temporary data that needs to be stored on disk

data/processed Contains processed raw data

tests Contains unit test cases for all functions

output Contains output from code

Use a build script Always use a build script to drive your code

Put functions in separate files Functions don't have to live in the same file as the calculations. Put them in a separate file, and include them using source()

But is it stylish? Use lintr to check your code for convention and obvious problems. Run it prior to every commit, e.g. lintr::lint("R/sample.R"). To show output from lintr in the Markers pane, select Code > Show Diagnostics from the menu. Add it as a dependent step in your build script.

Running tests

Use the following structure as a starting point:

  1. Functions are defined in files under src
  2. Create a test file in test for each file with functions that should be tested in

E.g.

  1. Functions are defined in src/sample.R
  2. A test file is created test/test-sample.R
  3. Load testthat package with the command library(testthat) in the R console
  4. Run the tests from the project root with the command test_file("./tests/testthat/test-sample.R") in the R console

rtemplateproject's People

Contributors

strandbygaard avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.