yonicd / sinew

Generate roxygen2 skeletons populated with information scraped from the function script.
https://yonicd.github.io/sinew/
Other
166 stars 15 forks source link

Broken interactive add-in #14

Closed grishin1 closed 7 years ago

grishin1 commented 7 years ago

I've installed the latest version and found that the interactive add-in is broken. Tried on 2 different machines with different files (Win only).

Listening on http://127.0.0.1:4424 Warning in file(con, "r") : file("") only supports open = "w+" and open = "w+b": using the former Warning: Error in eval: object 'zz' not found Stack trace (innermost first): 71: eval [#1] 70: eval 69: 68: do.call 67: observeEventHandler 3: shiny::runApp 2: shiny::runGadget 1: sinew:::interOxyAddIn ERROR: [on_request_read] connection reset by peer

yonicd commented 7 years ago

tested it on mac now. works. i'll look under the hood later in the day to get it to work with windows

grishin1 commented 7 years ago

no probs, thank you.

yonicd commented 7 years ago

it looks like it works on windows, it gets into trouble when it cant find a file to write to, and throws that warning

grishin1 commented 7 years ago

Well, having a previously saved file in the source editor and not being able to find it to write doesn't make sense to me. Simply because you can always have it at rstudioapi::getSourceEditorContext()$path.

Your reply suggested that you've used to and always expect users to work from a package project with R files under ./R/ subdirectory whereas I've used to feeding the add-in assorted R files.

And indeed when I tried from a) package project b) .R files from ./R subdirectory then it worked (strangely did crash again on the first try). It doesn't work from, say Documents with .R files from R subdirectory.

Anyway, your assumption has caught me by surprise. It's not very obvious and needs to be documented if you want it that way. I would prefer to be able to process any R file, not necessarily from within a package. Now it's not possible just to try it out -- you have to create a package first and this makes threshold higher.

yonicd commented 7 years ago

not sure i see where you are getting the error.

i can

grishin1 commented 7 years ago

I've tested on two Win 7/10 machines and here is what I see:

yonicd commented 7 years ago

i still dont see it.

i just closed all projects, restarted a session, loaded sinew

wrote the fn zz

zz <- function(a=2){
  utils::head(runif(10),a)
}

used the interactive addin, worked

#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param a PARAM_DESCRIPTION, Default: 2
#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples 
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @export 
#' @rdname zz
#' @seealso 
#'  
#' @import utils

saved the file to an arbitrary location, reran the addin and it works for both moga and makeOxygen inserts.

#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param a PARAM_DESCRIPTION, Default: 2
#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples 
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @export 
#' @rdname zz
#' @section SECTION_NAME
#' @seealso 
#'  
#' @import utils

i'll write a testthat script tonight to make it more formalized (even though i still dont know how testthat works with an interactive addin)

grishin1 commented 7 years ago

it would be useful now to get feedback from people using sinew.

yonicd commented 7 years ago

got it to break.

I've submitted sinew to EARL, so hopefully it will get more user input.

yonicd commented 7 years ago

breaks here. the main difference between what you had and what i had to change it to was to make it cran compatible. you wrote to globalEnv and that isnt allowed w cran pkgs. i rerouted everything to a temp environment.

yonicd commented 7 years ago

ok. try it now

it should auto source into a tempdir

notice also the new fn untangle

grishin1 commented 7 years ago

Just confirming... Now works with random R files/locations. One thing I've noticed was it couldn't source a file where one function was made using purrr's compose (no pkg;; prefixes by the way). The message was '...couldn't find function compose...'. After library(purrr) it did work.

yonicd commented 7 years ago

the addin searches any functions in the search path. so it would need to be loaded. not sure how to search for something not in the path yet.

yonicd commented 7 years ago

added a patch for random namespaces. purrr::compose should work now