Coder Social home page Coder Social logo

Documentation Suggestion about tinsel HOT 4 CLOSED

nteetor avatar nteetor commented on July 17, 2024
Documentation Suggestion

from tinsel.

Comments (4)

nteetor avatar nteetor commented on July 17, 2024 1

re: interactive sourcing
In tinsel 0.0.2, currently living on the dev branch, I added an RStudio addin to allow interactive decoratee sourcing. This works similarly to running a highlighted piece of code with Cmd+Return (mac) or Ctrl+Enter (windows/linux). I hope to have 0.0.2 released mid December. In the mean time feel free to use the development version of tinsel. I would appreciate any feedback regarding the new addin.

re: package authorship
This is my big challenge going forward. In the long run, I want decorating functions to be seamless, not a cumbersome extra step in package development. I would love, for example, to have many of the devtools functions related to R package development understand decorated functions. However, re-writing these functions is not productive at the moment, not unless tinsel becomes widely adopted. Here is a temporary fix for including decorated functions in a package.

Create a file, in this case hello.R, as you would,

#' Make Function Output more Exciting
#'
#' Concatenates \code{'!!!'} onto the end of a function's return value.
#'
#' @param f A function to decorate.
#'
#' @keywords internal
#' @export
excite <- function(f) {
  function() {
    paste0(f(), '!!!')
  }
}

#' Hello, world!
#'
#' This is an example function named 'hello' which returns 'Hello, world!'.
#'
#' \subsection{decorated by:} {
#'
#' This function is decorated by \link{excite}.
#'
#' }
#' @export
#. excite
hello <- function() {
 "Hello, world!"
}

(the decorator comment will not interfere with the roxygen comments)

Now create a file to overwrite the default definition of hello. Let's call the second file overwrite.R,

# load decorated functions and overwrite existing undecorated definitions

tinsel::source_decoratees('R/hello.R')

Finally, make sure your DESCRIPTION file has a collate section and lists overwrite.R as the last file (or at least after the file(s) with the decorated functions),

Package: example
Type: Package
....
Collate:
    'hello.R'
    'overwrite.R'

When you build and reload the package, hello is decorated and produces the expected output,

> tinsel::is.decorated(hello)
[1] TRUE
> hello()
[1] "Hello, world!!!!"

Add additional decorated functions to overwrite.R. I hope this helps while a better solution is developed.

Decorated functions can be tested, but only if the decorators are in the same file or defined ahead of time. Adding an additional parameter to source_decoratees allowing the programmer to list file(s) which contain decorator definitions could prove beneficial, #6.

from tinsel.

nteetor avatar nteetor commented on July 17, 2024 1

I would recommend using the addin(s). As you say source_decoratees() is far from interactive, but the addin(s) make tinsel and decorated functions feel much more interactive. The addin to be released in 0.0.2 will expand upon this.

As I said there's plenty to do to make decorators a part of package development, but I hope you will continue to try out tinsel. I certainly appreciate the feedback. This is how tinsel will get better.

Cheers, Nate.

from tinsel.

nteetor avatar nteetor commented on July 17, 2024

@drknexus , are you using the RStudio addin currently provided by tinsel?

from tinsel.

russellpierce avatar russellpierce commented on July 17, 2024

@nteetor I haven't yet, I was looking it over and deciding if and where it belonged in my toolbox. Certainly nice for things like memoising functions as a matter of course. The only other syntax-lite approach is something like...

(function(x) {x}) %>% memoise::memoise()

... but I like the decoration approach also.

from tinsel.

Related Issues (13)

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.