Comments (19)
The go engine was added from yihui/knitr#1330 by @hodgesds. Perhaps we should add a minimal example to this repo.
from knitr-examples.
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.
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.
One last thought... is go
on your $PATH
? I'm not sure if the code handles engine.path
.
from knitr-examples.
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.
Also, I had to change the snippet from
{go}
To
{r golang, engine='go'}
to get the error message
from knitr-examples.
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.
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.
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.
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.
Can you try running the minimal example in this repo:
./k 118-engine-go.Rmd
from knitr-examples.
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.
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.
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.
yes I got the same thing.
from knitr-examples.
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.
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.
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.
Hey @hodgesds ; Is there any perspective to have this fixed in the near future ?
Thanks
from knitr-examples.
Related Issues (20)
- While using the Python Engine, can I create and embed plots in my document? HOT 3
- Zero-width space in 065-rmd-chunk.Rmd HOT 3
- No kable output in nested for loops HOT 6
- engine bash not work on windows OS HOT 7
- Messages with false appendLF still gets seperated HOT 1
- knit.exit() for only this chunk
- Issues with commenting on code lines appearing in compiled PDF HOT 2
- Writing up a knitr document in windows but opening up in linux
- Issues in knitting on ggplots
- haskell engine error
- knitr syntax HOT 2
- Integration tests still valid ? HOT 2
- rgl update on CRAN seems to have modified the rgl example
- Recreate a mechanism to check knitr PR on a branch of knitr-examples HOT 1
- Add a GHA workflow to trigger a new check in knitr repo ? HOT 1
- Add a function in knitr to run example
- Fix issue with example 058 HOT 2
- Quarto PDF HOT 2
- Modifying powerpoint templates on Windows results on corrupt pptx file, aka "Powerpoint found a problem" HOT 5
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 knitr-examples.