Comments (4)
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.
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.
@drknexus , are you using the RStudio addin currently provided by tinsel?
from tinsel.
@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)
- backticks, white space, and variable names
- complete decorators compiler
- scanner `expected()` vs parser `expected()`
- node object for parse tree
- complete parser
- fix grammar
- Syntax for non REPL environments
- documenting decorated functions
- decorators in separate files HOT 1
- separate decorators test coverage
- passing connection to `source_decoratees`
- scanner statements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinsel.