Skip to content

Instantly share code, notes, and snippets.

View Non-Contradiction's full-sized avatar

Changcheng Li Non-Contradiction

View GitHub Profile
@Non-Contradiction
Non-Contradiction / package_wrap.R
Last active September 22, 2019 23:44
package wrap
julia_function <- function(func_name, pkg_name = "Main",
env = emptyenv()){
fname <- paste0(pkg_name, ".", func_name)
force(fname)
f <- function(...,
need_return = c("R", "Julia", "None"),
show_value = FALSE){
if (!isTRUE(env$initialized)) {
env$setup()
}
require(autodiffr)
ad_setup() # to ensure it is established
ores <- function(x){
x # Function will be the parameters. ofn is sum of squares
}
ores <- ad.variant(ores)
ofn <- function(x){
dll_file <- system("/home/rolf/Desktop/Julia/julia-d386e40c17/bin/julia -e \'print(Libdl.dlpath(\"libjulia\"))\'", intern = TRUE)
JuliaCall:::juliacall_initialize(dll_file)
JuliaCall:::juliacall_cmd('print("1\n")')
JuliaCall:::juliacall_cmd("using RCall")
JuliaCall:::juliacall_cmd("
function transfer_list(x)
dll_file <- system("julia -e \'print(Libdl.dlpath(\"libjulia\"))\'", intern = TRUE)
JuliaCall:::juliacall_initialize(dll_file)
JuliaCall:::juliacall_cmd('print("1\n")')
JuliaCall:::juliacall_cmd("using RCall")
JuliaCall:::juliacall_cmd("
function transfer_list(x)
dll_file <- system("julia -e \'print(Libdl.dlpath(\"libjulia\"))\'", intern = TRUE)
JuliaCall:::juliacall_initialize(dll_file)
JuliaCall:::juliacall_cmd('print("1\n")')
JuliaCall:::juliacall_cmd("using RCall")
JuliaCall:::juliacall_cmd("
function transfer_list(x)
dll_file <- system("julia -e \'print(Libdl.dlpath(\"libjulia\"))\'", intern = TRUE)
JuliaCall:::juliacall_initialize(dll_file)
JuliaCall:::juliacall_cmd('print("1\n")')
library(JuliaCall)
julia_setup()
julia_library("ForwardDiff")
f <- function(x) sum(x^2L)
julia_assign("ff", f)
julia_command("g = x -> ForwardDiff.gradient(ff, x);")
julia_command("g([2.0])")
## 1-element Array{Float64,1}:
## 4.0
@Non-Contradiction
Non-Contradiction / RRemez.R
Created September 24, 2017 16:54
Remez in R
fRunge = function(x) 1 / (1 + (5*x)^2)
library(JuliaCall)
julia_setup()
julia_install_package_if_needed("Remez")
julia_library("Remez")
## the following works for me with the latest version of JuliaCall
julia_call('R"fRunge"', 0)
## and this should also work
@Non-Contradiction
Non-Contradiction / JuliaCall in Jupyter R Notebook.ipynb
Created September 20, 2017 00:13
JuliaCall in Jupyter R Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
.julia <- new.env(parent = emptyenv())
julia <- new.env(parent = .julia)
.julia$bin_dir <-
system("julia -E 'println(JULIA_HOME)'", intern = TRUE)[1]
.julia$dll_file <-
system("julia -E 'println(Libdl.dllist()[1])'", intern = TRUE)[1]
.julia$dll <- dyn.load(.julia$dll_file, FALSE, TRUE)
.julia$include_dir <-