├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R └── godouble.R ├── README.md ├── gotest.Rproj ├── man ├── godouble.Rd └── hello.Rd └── src ├── Makevars ├── go └── src │ ├── main │ ├── main.c │ └── main.go │ └── twice │ └── twice.go └── gotest.h /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | .DS_Store 4 | .Rproj.user 5 | .Rhistory 6 | 7 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: gotest 2 | Type: Package 3 | Title: Trying to use go in R packages 4 | Version: 0.1.0 5 | Authors@R: c( person( "Romain", "Francois", email = "romain@thinkr.fr", role = c("aut", "cre")) ) 6 | Description: Trying to use go in R packages. 7 | Encoding: UTF-8 8 | LazyData: true 9 | RoxygenNote: 6.0.1.9000 10 | SystemRequirements: go, GNU make 11 | License: MIT + file LICENSE 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2017 2 | COPYRIGHT HOLDER: ThinkR 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(godouble) 4 | useDynLib(gotest) 5 | -------------------------------------------------------------------------------- /R/godouble.R: -------------------------------------------------------------------------------- 1 | #' Doubles an integer using go 2 | #' 3 | #' @param x an integer 4 | #' @useDynLib gotest 5 | #' @export 6 | godouble <- function(x) { 7 | .Call("godouble", x, PACKAGE = "gotest") 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## gotest 4 | 5 | This is an experiment to have go packages in R packages. 6 | See [here](https://romain.rbind.io/blog/2017/06/09/go-packages-in-r-packages/) 7 | for details. 8 | -------------------------------------------------------------------------------- /gotest.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | QuitChildProcessesOnExit: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /man/godouble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/godouble.R 3 | \name{godouble} 4 | \alias{godouble} 5 | \title{Doubles an integer using go} 6 | \usage{ 7 | godouble(x) 8 | } 9 | \arguments{ 10 | \item{x}{an integer} 11 | } 12 | \description{ 13 | Doubles an integer using go 14 | } 15 | -------------------------------------------------------------------------------- /man/hello.Rd: -------------------------------------------------------------------------------- 1 | \name{hello} 2 | \alias{hello} 3 | \title{Hello, World!} 4 | \usage{ 5 | hello() 6 | } 7 | \description{ 8 | Prints 'Hello, world!'. 9 | } 10 | \examples{ 11 | hello() 12 | } 13 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | .PHONY: go 2 | 3 | CGO_CFLAGS = "$(ALL_CPPFLAGS)" 4 | CGO_LDFLAGS = "$(PKG_LIBS) $(SHLIB_LIBADD) $(LIBR)" 5 | GOPATH = $(CURDIR)/go 6 | 7 | go: 8 | rm -f gotest.h 9 | CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) GOPATH=$(GOPATH) go build -o $(SHLIB) -x -buildmode=c-shared main 10 | -------------------------------------------------------------------------------- /src/go/src/main/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "_cgo_export.h" 4 | 5 | SEXP godouble(SEXP x){ 6 | return Rf_ScalarInteger( DoubleIt( INTEGER(x)[0] ) ) ; 7 | } 8 | -------------------------------------------------------------------------------- /src/go/src/main/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "C" 4 | 5 | import "twice" 6 | 7 | //export DoubleIt 8 | func DoubleIt(x int) int { 9 | return twice.Twice(x) ; 10 | } 11 | 12 | func main() {} 13 | -------------------------------------------------------------------------------- /src/go/src/twice/twice.go: -------------------------------------------------------------------------------- 1 | package twice 2 | 3 | func Twice(x int) int { 4 | return 2 * x ; 5 | } 6 | -------------------------------------------------------------------------------- /src/gotest.h: -------------------------------------------------------------------------------- 1 | /* Created by "go tool cgo" - DO NOT EDIT. */ 2 | 3 | /* package main */ 4 | 5 | /* Start of preamble from import "C" comments. */ 6 | 7 | 8 | 9 | 10 | /* End of preamble from import "C" comments. */ 11 | 12 | 13 | /* Start of boilerplate cgo prologue. */ 14 | #line 1 "cgo-gcc-export-header-prolog" 15 | 16 | #ifndef GO_CGO_PROLOGUE_H 17 | #define GO_CGO_PROLOGUE_H 18 | 19 | typedef signed char GoInt8; 20 | typedef unsigned char GoUint8; 21 | typedef short GoInt16; 22 | typedef unsigned short GoUint16; 23 | typedef int GoInt32; 24 | typedef unsigned int GoUint32; 25 | typedef long long GoInt64; 26 | typedef unsigned long long GoUint64; 27 | typedef GoInt64 GoInt; 28 | typedef GoUint64 GoUint; 29 | typedef __SIZE_TYPE__ GoUintptr; 30 | typedef float GoFloat32; 31 | typedef double GoFloat64; 32 | typedef float _Complex GoComplex64; 33 | typedef double _Complex GoComplex128; 34 | 35 | /* 36 | static assertion to make sure the file is being used on architecture 37 | at least with matching size of GoInt. 38 | */ 39 | typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; 40 | 41 | typedef struct { const char *p; GoInt n; } GoString; 42 | typedef void *GoMap; 43 | typedef void *GoChan; 44 | typedef struct { void *t; void *v; } GoInterface; 45 | typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; 46 | 47 | #endif 48 | 49 | /* End of boilerplate cgo prologue. */ 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | 56 | extern GoInt DoubleIt(GoInt p0); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | --------------------------------------------------------------------------------