I am running Java on Linux (CentOS), via the command line.
When I put the R command is a separate file, described in Section 1.4 of these docs,
I get the error:
Exception in thread "main" org.renjin.eval.EvalException: could not
find function 'engine.eval'
at org.renjin.eval.Context.evaluateFunction(Context.java:269)
at org.renjin.eval.Context.evaluateCall(Context.java:260)
at org.renjin.eval.Context.evaluate(Context.java:193)
at org.renjin.eval.Context.evaluateExpressionVector(Context.java:252)
at org.renjin.eval.Context.evaluate(Context.java:191)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:131)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:127)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:107)
at pkg3.Temp3.main(Temp3.java:31)
I have the CLASSPATH set correctly, because:
cd ~/rjtest
javac pkg3/Temp3.java
cd ~/rjtest
java pkg3.Temp3
produces:
x y
1 1 1.121
2 2 0.525
3 3 1.811
4 4 1.914
5 5 5.389
6 6 8.501
7 7 6.477
8 8 7.805
9 9 8.625
10 10 10.033
Call:
lm(formula = y ~ x, data = df)
Coefficients:
(Intercept) x
-0.902 1.113
Modifing the code to move the 3 engine.eval statements into script.R:
// engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
// engine.eval("print(df)");
// engine.eval("print(lm(y ~ x, df))");
engine.eval(new java.io.FileReader("/pathto/rjtest/pkg3/script.R"));
javac compiles with no error, but java gives the error.
The code engine.eval() is a Java statement. The Exception you're getting is Renjin telling you that there is no R function called engine.eval. Your script.R should contain:
df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))
print(df)
print(lm(y ~ x, df))"
Not:
engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))")
engine.eval("print(df)");
engine.eval("print(lm(y ~ x, df))")
Which is, coincidentally, valid R syntax, but not what you want.
Related
I´m just running the following example from GGEBiplotGUI package and of course, it works properly.
library(GGEBiplotGUI)
data("Ontario")
Ontario
GGEBiplot(Data = Ontario)
But when I download "Ontario" data and I want to run the above cited script on my PC. See the example below.
Ontario <- read.csv("Book.csv")
library(GGEBiplotGUI)
GGEBiplot(Data = Ontario)
The result is the following table (from column 0 to 10) taking numbers (From 1 to 17) as genotypes and "X" as another location.
See the result below please.
X BH93 EA93 HW93 ID93 KE93 NN93 OA93 RN93 WP93
1 ann 4.460 4.150 2.849 3.084 5.940 4.450 4.351 4.039 2.672
2 ari 4.417 4.771 2.912 3.506 5.699 5.152 4.956 4.386 2.938
3 aug 4.669 4.578 3.098 3.460 6.070 5.025 4.730 3.900 2.621
4 cas 4.732 4.745 3.375 3.904 6.224 5.340 4.226 4.893 3.451
5 del 4.390 4.603 3.511 3.848 5.773 5.421 5.147 4.098 2.832
6 dia 5.178 4.475 2.990 3.774 6.583 5.045 3.985 4.271 2.776
7 ena 3.375 4.175 2.741 3.157 5.342 4.267 4.162 4.063 2.032
8 fun 4.852 4.664 4.425 3.952 5.536 5.832 4.168 5.060 3.574
9 ham 5.038 4.741 3.508 3.437 5.960 4.859 4.977 4.514 2.859
10 har 5.195 4.662 3.596 3.759 5.937 5.345 3.895 4.450 3.300
11 kar 4.293 4.530 2.760 3.422 6.142 5.250 4.856 4.137 3.149
12 kat 3.151 3.040 2.388 2.350 4.229 4.257 3.384 4.071 2.103
13 luc 4.104 3.878 2.302 3.718 4.555 5.149 2.596 4.956 2.886
14 m12 3.340 3.854 2.419 2.783 4.629 5.090 3.281 3.918 2.561
15 reb 4.375 4.701 3.655 3.592 6.189 5.141 3.933 4.208 2.925
16 ron 4.940 4.698 2.950 3.898 6.063 5.326 4.302 4.299 3.031
17 rub 3.786 4.969 3.379 3.353 4.774 5.304 4.322 4.858 3.382
How can I fix this problem? I mean, in order to avoid "rownames" and "x" as a variables in the GGEBiplotGUI analysis.
I have also tried with these codes and they didn´t work:
attributes(Ontario)$row.names <- NULL
print(Ontario, row.names = F)
row.names(Ontario) <- NULL
Ontario[, -1] ## It deletes the first column not the 0 one.
Many thanks in advance!
This code worked properly.
Ontario <- read.csv("Libro.csv")
rownames(Ontario)<-Ontario$X
Ontario1<-Ontario[,-1]
library(GGEBiplotGUI)
GGEBiplot(Data = Ontario)
I'm using PackageCompiler hoping to create an executable that eliminates just-in-time compilation overhead.
The documentation explains that I must define a function julia_main to call my program's logic, and write a "snoop file", a script that calls functions I wish to precompile. My julia_main takes a single argument, the location of a file containing the input data to be analysed. So to keep things simple my snoop file simply makes one call to julia_main with a particular input file. So I'd hope to see the generated executable run nice and fast (no compilation overhead) when executed against that same input file.
But alas, that's not what I see. In a fresh Julia instance julia_main takes approx 74 seconds for the first execution and about 4.5 seconds for subsequent executions. The executable file takes approx 50 seconds each time it's called.
My use of the build_executable function looks like this:
julia> using PackageCompiler
julia> build_executable("d:/philip/source/script/julia/jsource/SCRiPTMain.jl",
"testexecutable",
builddir = "d:/temp/builddir4",
snoopfile = "d:/philip/source/script/julia/jsource/snoop.jl",
compile = "all",
verbose = true)
Questions:
Are the above arguments correct to achieve my aim of an executable with no JIT overhead?
Any other advice for me?
Here's what happens in response to that call to build_executable. The lines from Start of snoop file execution! to End of snoop file execution! are emitted by my code.
Julia program file:
"d:\philip\source\script\julia\jsource\SCRiPTMain.jl"
C program file:
"C:\Users\Philip\.julia\packages\PackageCompiler\CJQcs\examples\program.c"
Build directory:
"d:\temp\builddir4"
Executing snoopfile: "d:\philip\source\script\julia\jsource\snoop.jl"
Start of snoop file execution!
┌ Warning: The 'control file' contains the key 'InterpolateCovariance' with value 'true' but that is not supported. Pass a value of 'false' or omit the key altogether.
└ # ValidateInputs d:\Philip\Source\script\Julia\JSource\ValidateInputs.jl:685
Time to build model 20.058000087738037
Saving c:/temp/SCRiPT/SCRiPTModel.jls
Results written to c:/temp/SCRiPT/SCRiPTResultsJulia.json
Time to write file: 3620 milliseconds
Time in method runscript: 76899 milliseconds
End of snoop file execution!
[ Info: used 1313 out of 1320 precompile statements
Build static library "testexecutable.a":
atexit_hook_copy = copy(Base.atexit_hooks) # make backup
# clean state so that any package we use can carelessly call atexit
empty!(Base.atexit_hooks)
Base.__init__()
Sys.__init__() #fix https://github.com/JuliaLang/julia/issues/30479
using REPL
Base.REPL_MODULE_REF[] = REPL
Mod = #eval module $(gensym("anon_module")) end
# Include into anonymous module to not polute namespace
Mod.include("d:\\\\temp\\\\builddir4\\\\julia_main.jl")
Base._atexit() # run all exit hooks we registered during precompile
empty!(Base.atexit_hooks) # don't serialize the exit hooks we run + added
# atexit_hook_copy should be empty, but who knows what base will do in the future
append!(Base.atexit_hooks, atexit_hook_copy)
Build shared library "testexecutable.dll":
`'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe' --sysroot 'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root' -shared '-DJULIAC_PROGRAM_LIBNAME="testexecutable.dll"' -o testexecutable.dll -Wl,--whole-archive testexecutable.a -Wl,--no-whole-archive -std=gnu99 '-IC:\Users\philip\AppData\Local\Julia-1.2.0\include\julia' -DJULIA_ENABLE_THREADING=1 '-LC:\Users\philip\AppData\Local\Julia-1.2.0\bin' -Wl,--stack,8388608 -ljulia -lopenlibm -m64 -Wl,--export-all-symbols`
Build executable "testexecutable.exe":
`'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe' --sysroot 'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root' '-DJULIAC_PROGRAM_LIBNAME="testexecutable.dll"' -o testexecutable.exe 'C:\Users\Philip\.julia\packages\PackageCompiler\CJQcs\examples\program.c' testexecutable.dll -std=gnu99 '-IC:\Users\philip\AppData\Local\Julia-1.2.0\include\julia' -DJULIA_ENABLE_THREADING=1 '-LC:\Users\philip\AppData\Local\Julia-1.2.0\bin' -Wl,--stack,8388608 -ljulia -lopenlibm -m64`
Copy Julia libraries to build directory:
7z.dll
BugpointPasses.dll
libamd.2.4.6.dll
libamd.2.dll
libamd.dll
libatomic-1.dll
libbtf.1.2.6.dll
libbtf.1.dll
libbtf.dll
libcamd.2.4.6.dll
libcamd.2.dll
libcamd.dll
libccalltest.dll
libccolamd.2.9.6.dll
libccolamd.2.dll
libccolamd.dll
libcholmod.3.0.13.dll
libcholmod.3.dll
libcholmod.dll
libclang.dll
libcolamd.2.9.6.dll
libcolamd.2.dll
libcolamd.dll
libdSFMT.dll
libexpat-1.dll
libgcc_s_seh-1.dll
libgfortran-4.dll
libgit2.dll
libgmp.dll
libjulia.dll
libklu.1.3.8.dll
libklu.1.dll
libklu.dll
libldl.2.2.6.dll
libldl.2.dll
libldl.dll
libllvmcalltest.dll
libmbedcrypto.dll
libmbedtls.dll
libmbedx509.dll
libmpfr.dll
libopenblas64_.dll
libopenlibm.dll
libpcre2-8-0.dll
libpcre2-8.dll
libpcre2-posix-2.dll
libquadmath-0.dll
librbio.2.2.6.dll
librbio.2.dll
librbio.dll
libspqr.2.0.9.dll
libspqr.2.dll
libspqr.dll
libssh2.dll
libssp-0.dll
libstdc++-6.dll
libsuitesparseconfig.5.4.0.dll
libsuitesparseconfig.5.dll
libsuitesparseconfig.dll
libsuitesparse_wrapper.dll
libumfpack.5.7.8.dll
libumfpack.5.dll
libumfpack.dll
libuv-2.dll
libwinpthread-1.dll
LLVM.dll
LLVMHello.dll
zlib1.dll
All done
julia>
EDIT
I was afraid that creating a minimal working example would be hard, but it was straightforward:
TestBuildExecutable.jl contains:
module TestBuildExecutable
Base.#ccallable function julia_main(ARGS::Vector{String}=[""])::Cint
#show sum(myarray())
return 0
end
#Function which takes approx 8 seconds to compile. Returns a 500 x 20 array of 1s
function myarray()
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
# PLEASE EDIT TO INSERT THE MISSING 496 LINES, EACH IDENTICAL TO THE LINE ABOVE!
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
end
end #module
SnoopFile.jl contains:
module SnoopFile
currentpath = dirname(#__FILE__)
push!(LOAD_PATH, currentpath)
unique!(LOAD_PATH)
using TestBuildExecutable
println("Start of snoop file execution!")
TestBuildExecutable.julia_main()
println("End of snoop file execution!")
end # module
In a fresh Julia instance, julia_main takes 8.3 seconds for the first execution and half a millisecond for the second execution:
julia> #time TestBuildExecutable.julia_main()
sum(myarray()) = 10000
8.355108 seconds (425.36 k allocations: 25.831 MiB, 0.06% gc time)
0
julia> #time TestBuildExecutable.julia_main()
sum(myarray()) = 10000
0.000537 seconds (25 allocations: 82.906 KiB)
0
So next I call build_executable:
julia> using PackageCompiler
julia> build_executable("d:/philip/source/script/julia/jsource/TestBuildExecutable.jl",
"testexecutable",
builddir = "d:/temp/builddir15",
snoopfile = "d:/philip/source/script/julia/jsource/SnoopFile.jl",
verbose = false)
Julia program file:
"d:\philip\source\script\julia\jsource\TestBuildExecutable.jl"
C program file:
"C:\Users\Philip\.julia\packages\PackageCompiler\CJQcs\examples\program.c"
Build directory:
"d:\temp\builddir15"
Start of snoop file execution!
sum(myarray()) = 10000
End of snoop file execution!
[ Info: used 79 out of 79 precompile statements
All done
Finally, in a Windows Command Prompt:
D:\temp\builddir15>testexecutable
sum(myarray()) = 1000
D:\temp\builddir15>
which took (by my stopwatch) 8 seconds to run, and it takes 8 seconds to run every time it's executed, not just the first time. This is consistent with the executable doing a JIT compile every time it's run, but the snoop file is designed to avoid that!
Version information:
julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-6700 CPU # 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 8
JULIA_EDITOR = "C:\Users\Philip\AppData\Local\Programs\Microsoft VS Code\Code.exe"
Looks like you are using Windows.
At some point PackageCompiler.jl will be mature for Windows at which you can try it.
The solution was indeed to wait for progress on PackageCompilerX, as suggested by #xiaodai.
On 10 Feb 2020 what was formerly PackageCompilerX became a new (version 1.0 of) PackageCompiler, with a significantly changed API, and more thorough documentation.
In particular, the MWE above (mutated for the new API to PackageCompiler) now works correctly without any JIT overhead.
I want to create Multicommodity Min Cost Flow instances with the help of
Mnetgen but I have problems with the file called "batch" whose first lines are given by
# Batch file for generating MMCF problems with the mnetgen random generator
#
# For each n in {64, 128, 256} generates 12 instances for each pair (n, k)
# with k in {4, 8, 16 , ... , n}, using as input the parameters found
# in pr{n}.{k}/{n}-{k}-{h}.inp for h in {1, ... , 12}. The instances
# are left in the directory pr{n}.{k}
#
# At the end of the file, commented out, there are the instructions for
# generating the groups with n = 512 and n = 768: in the latter case,
# however, only 6 instances for each group are generated.
#
# In a Unix environment, simply type "source batch" or "csh < batch"
foreach i ( 64 )
foreach j ( 4 8 16 32 64 )
foreach h ( 1 2 3 4 5 6 7 8 9 10 11 12 )
mnetgen pr$i.$j/$i-$j-$h.inp pr$i.$j/$i-$j-$h
end
end
end
...
What did I so far? First I added #include <cstring> to mnetgen.c to avoid errors. Then I typed make to get an executable file mnetgen. The last step would be to generate the instances by using the batch-file.
Using the hint in last comment line I get either
bash: batch: Zeile 14: Syntaxfehler beim unerwarteten Wort »(«
bash: batch: Zeile 14: 'foreach i ( 64 )'
or
mnetgen: Command not found.
How can I fix that?
You are trying to run a csh shell in bash.
To fix that, either run
csh myshell
or add on the first line:
#!/bin/csh
When running your command, Unix/linux will check the first line which will be seen as a kind of magic number and will prefix it by /bin/csh.
(there are better ways to do that maybe with #!/bin/env csh)
and for your mnetgen command which is not found, I suggest that you add the full path of your command in your script or add it to the system PATH.
I am trying to compile a code that hasn't been developed with the newest standards in mind. I am using the gfortran compiler and get a few errors that I can't correct.
A partner of mine uses the Intel Visual Fortran compiler in MS Visual Studio and doesn't get any errors. Below are the relevant sections of code and their errors. Insight into any of these would be greatly appreciated.
Error 1:
flow.for:63.63:
3 *gjmh_old(j)*abs(gjmh_old(j))/2.0d0/dens_fjmh(j) )
1
Error: Expected a right parenthesis in expression at (1)
Corresponding code:
sum_dpjmh_old= 1.0/2.0*(dens_jmh(j)+dens_old(j))*grav*(dzc(j)/2.0d0) !!!!
1 + ( gavg_old(j)*gavg_old(j)/dens_mom(j)
1 -gjmh_old(j)*gjmh_old(j)/dmom_jmh(j) )
3 + 1.0/2.0*
3 ( fric(j)*dzc(j)/2.0/dhyd(j)
3 *gavg_old(j)*abs(gavg_old(j))/2.0d0/dens_fric(j)
3 +fjmh(j)*dzc(j)/2.0/dhyd(j)
3 *gjmh_old(j)*abs(gjmh_old(j))/2.0d0/dens_fjmh(j) )
Error 2:
flow.for:78.13:
1 + ( gavg(j)*gavg(j)/dens_momn(j)
1
Error: Missing exponent in real number at (1)
Corresponding Code:
sum_dpjmh = 1.0/2.0*(dens_jmhn(j)+dens_ch(j))*grav*(dzc(j)/2.0d0) !!!!
1 + ( gavg(j)*gavg(j)/dens_momn(j)
1 -gjmh(j)*gjmh(j)/dmom_jmhn(j) )
3 + 1.0/2.0*
3 ( fric(j)*(dzc(j)/2.0)/dhyd(j)
3 *gavg(j)*abs(gavg(j))/2.0d0/dens_ch(j)
3 + fjmh(j)*(dzc(j)/2.0)/dhyd(j)
3 *gjmh(j)*abs(gjmh(j))/2.0d0/dens_jmhn(j) )
Error 3:
flow.for:684.72:
3 /dens_fjmh(j) )
1
Error: Syntax error in argument list at (1)
Corresponding code:
gjmh(j) = gjmh_old(j) + dt/dzc(j)*(
1 phi*2.0d0*(pjmh(j)-p(j))
1 + (1.0-phi)*2.0d0*(pjmh_old(j)-p_old(j))
1 - 2.0d0*( gavg_old(j)*gavg_old(j)/dens_mom(j)
1 -gjmh_old(j)*gjmh_old(j)/dmom_jmh(j) )
4 - dens_jmh(j)*grav*dzc(j)
3 - fjmh(j)*dzc(j)/2.0d0/dhyd(j)*gjmh_old(j)*abs(gjmh_old(j))
3 /dens_fjmh(j) )
It seems your code is not well formatted. If you are trying to use fixed format, you should follow the request of fixed format, as http://nf.nci.org.au/training/FortranBasic/slides/slides.005.html.
Or following instructions in http://en.wikipedia.org/wiki/Fortran#Fixed_layout_and_punched_cards:
Column 1 contains *, ! or C for comments.
Column 6 for continuation.
Another way is to convert fixed format to free format, but since your code is not well formatted, most converter may be not working well.
I have a program dnapars
I execute the program from command line as following:
./dnapars
The program then prompts me some message as a user menu from where I have to select a series of options in the order R U Y R. And then I copy the output file (outfile) in another result file.
I wrote the following script, but the execution hangs where it is supposed to execute the R option
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
do
cp ../../../EditDistanceRandomParsimonator/RAxML_parsimonyTree.test4D20RI$i.0 intree
./dnapars
R <----- This doesn't execute
U
Y
R
cp outfile result$i
done
How can I make the script to run the options R U Y R under the dnapars program ?
You may be able to use a shell here document, for example:
./dnapars <<EndOfOptions
R
U
Y
R
EndOfOptions
This will generally work if the program reads its options from stdin.