Giter VIP home page Giter VIP logo

Comments (19)

yihui avatar yihui commented on June 14, 2024

The go engine was added from yihui/knitr#1330 by @hodgesds. Perhaps we should add a minimal example to this repo.

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

Just a side note here; I tried configuring the block like this:

{r golang, engine='go', engine.opts='run', engine.path='/usr/local/go/bin/go'}

but I get the following:

go run: no go files listed

It's the same output when I run go run on my terminal without passing a source to execute. I'm not sure but it looks to me that there might be something wrong or missing with the engine configuration

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

Here is an example of using a go package (non executable).

Hello Go!
```{go eval=FALSE}
package hello 

func HelloWorld(){
   println("hello world!")
}```

And for a main (executable) package:

I can run Go!
```{go}
package main 

func main(){
   println("hello world!")
}```

Note that it will automatically call go fmt on the source.

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

One last thought... is go on your $PATH? I'm not sure if the code handles engine.path.

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

Sorry but that still doesn't work.
I created a fresh notebook from Rstudio and copied the snippets above. The blocks are not recognized as 'runable' ( no play button on the right corner). I tried to execute all anyways but nothing happens.

Next I added the following to my file:

library(knitr)
knit_engines$get("go")

The blocks still are not recognized, but now when I execute the file, the block that contains the main function returns the following:

/bin/sh: 1: go: not found

I double checked and my Go installation is on path, I also can confirm that because its my default language for development and I use other tools like Atom.

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

Also, I had to change the snippet from

{go}

To

{r golang, engine='go'}

to get the error message

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

What happens when you run system("echo $PATH")? The error /bin/sh: 1: go: not found would indicate that go isn't on your $PATH

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

When I run the command from Rstudio I see this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

But when I check the $PATH from my terminal I get this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/bin:/home/felipevl/go/bin

Note how they are different.
Am I missing something ?

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

This might be of help, perhaps try starting Rstudio from the terminal if you want to inherit the same path.

touch ~/.Renviron | R_PATH="PATH=$PATH" | echo $R_PATH >  ~/.Renviron

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

I added my system PATH to the file as described on that link you sent me, and now I started rstudio from terminal. When I run system("echo $PATH") I see the following:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/bin:/home/felipevl/go/bin

Now it seems to be present on the path inside Rstudio as well.

I typed the same block again

{r golang, engine='go'}
package main 

func main(){
   println("hello world!")
}

And now I'm getting the following :

go: unknown subcommand "/tmp/RtmpxYjuJJ/chunk-code31bd34e27ecb." Run 'go help' for usage.

The block is still unrecognized as 'runnable'

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

Can you try running the minimal example in this repo:
./k 118-engine-go.Rmd

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

I opened Rstudio via command line and checked the path, the Go installation is present.

I downloaded the file and created a new notebook. None of the blocks are recognized as executable and only the last one has the code colored.

I clicked the 'Run All ' command and only the last block produced the following output:

go: unknown subcommand "/tmp/RtmpNJF891/chunk-code220b54e7b85."
Run 'go help' for usage.

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

It looks like that the go compiler is being found and is responding, but the block or the execution unit is not being passed to it.

I changed the last block to this {r engine='go', engine.opts='run'} and the output changed to:

go run: no go files listed

go run is what you run when trying a script like that, its just saying that there is nothing to execute.

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

I can't really help you debug your RStudio setup, please run the minimal example that is in this repo.

> require('knitr')
> knit('~/git/knitr-examples/118-engine-go.Rmd')

processing file: ~/git/knitr-examples/118-engine-go.Rmd
  |...........                                                      |  17%
  ordinary text without R code

  |......................                                           |  33%
label: unnamed-chunk-1 (with options) 
List of 2
 $ eval  : logi FALSE
 $ engine: chr "go"

  |................................                                 |  50%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-2 (with options) 
List of 1
 $ engine: chr "go"

running: go run ./code77451bd44b11.go
  |......................................................           |  83%
  ordinary text without R code

  |.................................................................| 100%
label: unnamed-chunk-3 (with options) 
List of 1
 $ engine: chr "go"

running: go run ./code7745662a0cba.go

output file: 118-engine-go.md

[1] "118-engine-go.md"

The contents of 118-engine-go.md should be as follows:

Hello package!

package hello 

func HelloWorld(){
   println("hello world!")
}

Hello main!

package main 

func main(){
   println("hello world!")
}
## hello world!

Or specify an engine:

package main

func main(){
   println("hello world!")
}
## hello world!

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

yes I got the same thing.

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

When running on the terminal I see the hidden go file being created, but I think the same is not true when running on Rstudio. It looks to me that the code should be on the /tmp folder but the same has nothing there. Could this snippet be the problem ? f = tempfile("code", ".", fileext = ".go")

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

The code you have, when running on Rstudio output this:

go: unknown subcommand "/tmp/RtmprHeIZi/chunk-code2f28c15b829."

See how the path ends with a . instead of an full extension ?

from knitr-examples.

hodgesds avatar hodgesds commented on June 14, 2024

interesting.... I'm guessing something here needs updated. If you trying using the knit command for a .Rmd file it should work.

from knitr-examples.

prvst avatar prvst commented on June 14, 2024

Hey @hodgesds ; Is there any perspective to have this fixed in the near future ?
Thanks

from knitr-examples.

Related Issues (20)

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.