GithubHelp home page GithubHelp logo

jameshwade / cookiecutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from felixhenninger/cookiecutter

0.0 1.0 0.0 4.4 MB

Generate Project Files from a Template

Home Page: https://felixhenninger.github.io/cookiecutter

R 75.98% SCSS 24.02%

cookiecutter's Introduction


cookiecutter for R

The cookiecutter package for R makes it easy to create new projects and files based on templates. It can create directory structures and files, and customizes their contents based on predefined settings.

The package implements the core functionality of the excellent and much more flexible Python implementation, and complements the likewise fantastic usethis package that automates development steps within a project.


Usage ๐Ÿช

Installation ๐Ÿ“ฆ

The package is available on CRAN, so that you can install it via

install.packages('cookiecutter')

Alternatively, if you like to live on the bleeding edge, you can install the development version:

devtools::install_github('felixhenninger/cookiecutter@main')

Making cookies ๐Ÿ‘ฉโ€๐Ÿณ

To get started, you'll need a cookiecutter template, and a place to extract it. For example, starting from a template directory you could run:

cookiecutter::bake(
  'template_directory',
  'output_directory'
)

If you've downloaded a template as a compressed archive or a directory, you can clone it locally.

cookiecutter::bake(
  'template.zip',
  'output_directory'
)

Crafting a template ๐Ÿ› 

In principle, any directory you already have can serve as a cookiecutter template. Out of the box, if you use it as template, cookiecutter will simply copy the directory for you. Likewise, if you create a zip, .tar or .tar.gz archive of your directory, cookiecutter will unpack it into the output location.

However, there are many more things you can do to make your template more user-friendly. Specifically, cookiecutter will change the names and contents of files according to your specifications. The way this works is that you can insert a placeholder, {{ cookiecutter.my_variable }} inside a file (or in its name or directory name), and cookiecutter will try to replace this placeholder (curly braces and all) with the contents of my_variable.

If you use the placeholder alone, your users will need to supply the values of any variables when they bake the template, like so (here, we set the variable topping, which you could use in a file or file name via {{ cookiecutter.topping }}):

cookiecutter::bake(
  'template.zip',
  'output_directory',
  extra_context = list(
    topping = 'sprinkles'
  )
)

You can help your users figure out which variables are available by adding a cookiecutter.json file to your template directory. If you do so, cookiecutter will know about the variables it needs, and prompt users to fill in or to choose a value. It will provide a default, or a list of choices, respectively.

The format of this file is documented fully in the Python cookiecutter documentation, but to give you an impression of the options, here's an example:

{
  "cookie_eating_sound": "Om nom nom nom",
  "cookie_local_term": ["cookie", "biscuit"]
}

Limitations โš ๏ธ

The cookiecutter package for R aims to be compatible with its big sibling, but at present implements only a subset of their functionality.

Of course, few of these issues are insurmountable, and they are great places to contribute!

  • We don't (yet) provide the full extent of the Jinja templating language that cookiecutter uses. Specifically, at present, we don't support logic in templates.
  • Naturally, we don't support Python code in templates.
  • We don't currently support cloning templates directly from a git repository. You can still download the repository contents and clone from a directory or an archive.
  • We don't support ~/.cookiecutterrc files.
  • We don't support running scripts automatically after populating a template.

If you're looking for the full power of the original, we wholeheartedly recommend using it โ€” our clone is designed to be a stop-gap, not a replacement. If we can whet your appetite, that's a win in our book!

cookiecutter's People

Contributors

felixhenninger avatar aidakreider avatar

Watchers

 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.