While trying to load the RProvider.fsx, I get a error that the Assembly reference RDotNet.dll was not found or is invalid
I'm following this walktrough: http://bluemountaincapital.github.io/FSharpRProvider/Statistics-QuickStart.html
Using Visual Studio 15 (I use the free community edition)
Create new F# console project: UseNuGetPackage (Exact steps NOT given)
Download and install R (Exact steps NOT given)
Install R Type provider
In Visual Studio using Solution Explorer
Right click F# project e.g. UseNuGetPackage
Select: Manage NuGet Packages for Solution
Click Browse
Enter: RProvider
Click check box on the left of Project
Click Install
Click OK
The Visual Studio output window shows:
Attempting to gather dependencies information for package 'RProvider.1.1.15' with respect to project 'UseNuGetPackage', targeting '.NETFramework,Version=v4.5.2'
Attempting to resolve dependencies for package 'RProvider.1.1.15' with DependencyBehavior 'Lowest'
Resolving actions to install package 'RProvider.1.1.15'
Resolved actions to install package 'RProvider.1.1.15'
Adding package 'DynamicInterop.0.7.4' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'DynamicInterop.0.7.4' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'DynamicInterop.0.7.4' to 'packages.config'
Successfully installed 'DynamicInterop 0.7.4' to UseNuGetPackage
Adding package 'R.NET.Community.1.6.4' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'R.NET.Community.1.6.4' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'R.NET.Community.1.6.4' to 'packages.config'
Successfully installed 'R.NET.Community 1.6.4' to UseNuGetPackage
Adding package 'R.NET.Community.FSharp.1.6.4' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'R.NET.Community.FSharp.1.6.4' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'R.NET.Community.FSharp.1.6.4' to 'packages.config'
Successfully installed 'R.NET.Community.FSharp 1.6.4' to UseNuGetPackage
Adding package 'RProvider.1.1.15' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'RProvider.1.1.15' to folder 'c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages'
Added package 'RProvider.1.1.15' to 'packages.config'
Successfully installed 'RProvider 1.1.15' to UseNuGetPackage
========== Finished ==========
Notice in the image below the green check mark identifying that the package is installed.
Notice in the image below the new references for the project.
To get the following two statements to work we need to verify some paths.
#I "../packages/RProvider.1.0.11"
#load "RProvider.fsx"
The example given is specific to a version and as we know versions change so check the version of the DLL that will be used.
In the F# project
Right click the RProvider reference
Right click Properties
Here is the full path so you don't have to squint
c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\packages\RProvider.1.1.15\lib\net40\RProvider.dll
The example is using version RProvider.1.0.11 and we have RProvider.1.1.15
so we need to update the line from the example to
#I "../packages/RProvider.1.1.15"
If you look a lot of examples where you download a package from NuGet and then use it with F# Interactive you will see the same pattern to get it started.
#I "../packages/<Name_XYZ>.<Version>"
#load "<Name_XYZ>.fsx"
This is because this code assumes that you have used NuGet to install the needed DLLs in a VS project and that the DLLS are in a packages directory that is relative to the source code for the project. If you look back at the listing I gave for the output window you will see the copying of the DLLs.
Here they are shown in File Explorer
So how does F# Interactive know how to find the DLLs when it only has a relative path.
Now for the magical missing part that we leave out because it is a
conspiracy to test newbies. :-)
F# Interactive has the property __SOURCE_DIRECTORY__ that gives the location of the source directory in a VS project. This can be seen in F# Interactive with
printfn __SOURCE_DIRECTORY__
which for my example is
c:\users\eric\documents\visual studio 2015\Projects\UseNuGetPackage\UseNuGetPackage
val it : unit = ()
if you get a directory containing AppData then restart F# Interactive.
This can be checked with File Explorer
sure enough this is the source directory for the project.
More importantly the path from the source directory to the NuGet packages is
../packages
So all the paths look good.
Now that we have updated and checked the script lines to load the DLL give it a try.
We get the error:
error FS0082: Could not resolve this reference. Could not locate the assembly "RDotNet.FSharp.dll".
The problem is the specific versions mentioned in RProvider.fsx
// Standard NuGet locations for R.NET
#I "../R.NET.Community.1.5.16/lib/net40"
#I "../R.NET.Community.FSharp.0.1.9/lib/net40"
If we substitute out #load "RProvider.fsx" with
#r "../packages/R.NET.Community.1.6.4/lib/net40/RDotNet.dll"
#r "../packages/R.NET.Community.FSharp.1.6.4/lib/net40/RDotNet.FSharp.dll"
#r "../packages/RProvider.1.1.15/lib/net40/RProvider.dll"
#r "../packages/RProvider.1.1.15/lib/net40/RProvider.Runtime.dll"
open RProvider
do fsi.AddPrinter(fun (synexpr:RDotNet.SymbolicExpression) -> synexpr.Print())
open System
open RDotNet
open RProvider
open RProvider.graphics
open RProvider.stats
The example works. e.g.
// Random number generator
let rng = Random()
let rand () = rng.NextDouble()
// Generate fake X1 and X2
let X1s = [ for i in 0 .. 9 -> 10. * rand () ]
let X2s = [ for i in 0 .. 9 -> 5. * rand () ]
// Build Ys, following the "true" model
let Ys = [ for i in 0 .. 9 -> 5. + 3. * X1s.[i] - 2. * X2s.[i] + rand () ]
let dataset =
namedParams [
"Y", box Ys;
"X1", box X1s;
"X2", box X2s; ]
|> R.data_frame
let result = R.lm(formula = "Y~X1+X2", data = dataset)
let coefficients = result.AsList().["coefficients"].AsNumeric()
let residuals = result.AsList().["residuals"].AsNumeric()
let summary = R.summary(result)
summary.AsList().["r.squared"].AsNumeric()
R.plot result
Also as Tomas noted in his answer there is a bug with the version numbers in the fsx file, but he was able to update the source code and make a new alpha version.
:)
Hopefully I gave enough detail that the next time you see one of these examples on using a NuGet package with F# Interactive and have a problem you can resolve it.
There is a bug in RProvider.fsx where it references a wrong version of R.NET. The version 1.1.16-alpha has a fix for this, but we did not release a new non-beta yet.
Can you check that this works fine if you install 1.1.16-alpha?
The link of #GuyCoder helped me: How does F# Interactive #I command know about project path?
I searched the missing .dll files on my computer, and pasted in the parent folder of the source directory.
After this everything worked fine
#I "../packages/RProvider.1.1.15"
(*
#r "RDotNet.dll"
#r "RDotNet.FSharp.dll"
These 2 are unnecessary*)
#load "RProvider.fsx"
open System
open RDotNet
open RProvider
open RProvider.graphics
open RProvider.stats
EDIT:
I first downloaded the nuget packages Rdotnet & Rdotnet.Fsharp, then I searched on my computer for the dll's,
Then I copied these files and pasted it in the directory I was working in:
Which you also can find with __SOURCE_DIRECTORY__
Related
In Python, if I install mambaforge or conda then I can make a file with extension .yml and then inside it list the name of packages I want to install alongside their specific versions. How can I do a similar way of installing packages in Julia?
I understand that if I have already installed Julia packages by addcommand in package manager, then I have a file named Project.toml which I can use to install the same packages later. However, this still does not look as good as Python's way of installing packages.
Upon further investigation I realized that to install Julia packages from an empty Prokect.tomlfile, I should add [deps]in the file followed by the name of packages I want and then give each package a uuidwhich can be found here. For example:
[deps]
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
After all , this is still tedious as it needs to find all those uuids.
How can I install packages in Julia the same way I described for Python?
Is there a particular reason that you want to write package names to a .yml file and then read the packages from there? After all, you can generate the Project file and add multiple dependencies automatically:
(#v1.8) pkg> generate MyProject # or whatever name you like
(#v1.8) pkg> activate MyProject
(MyProject) pkg> add Countries Crayons CSV # some example packages
(In recent versions of Julia, an installation prompt will appear if a package isn't already installed).
Speaking from experience, learning to use environments in Julia can be challenging to a new user, but rewarding! The documentation for Pkg.jl are helpful here.
If you are just assembling an environment for your own code, there is probably no need for you to manually edit Project.toml. On the other hand, if you are maintaining a package, you might wish to edit the file directly (e.g., for specifying compatability).
Maybe you can use this:
using TOML
using HTTP
using DataStructures
## Get the Registry.toml file if it already doesn't exist in the current directory
function raed_reg()
if !isfile("Registry.toml")
HTTP.download(
"https://raw.githubusercontent.com/JuliaRegistries/General/master/Registry.toml",
"Registry.toml"
)
end
reg = TOML.parsefile("Registry.toml")["packages"]
return reg
end
## Find the UUID of a specific package from the Registry.toml file
function get_uuid(pkg_name)
reg = raed_reg()
for (uuid, pkg) in reg
if pkg["name"] == pkg_name
return uuid
end
end
end
## Create a dictionary for the gotten UUIDs, by setting the name = UUID and convert it to a project.toml file
function create_project_toml(Pkgs::Vector{String})
reg = raed_reg()
pkgs_names_uuid = OrderedDict{AbstractString, AbstractString}()
pkgs_names_uuid["[deps]"] = ""
for pkg in Pkgs
_uuid = get_uuid(pkg)
pkgs_names_uuid[pkg] = _uuid
end
open("project.toml", "w") do io
TOML.print(io, pkgs_names_uuid)
end
end
## Test on the packages "ClusterAnalysis" and "EvoTrees"
create_project_toml(["ClusterAnalysis", "EvoTrees"])
I want to change the Package directory in Julia. The default is
"~/.julia/v0.4"
I want to move it to /opt/julia/v0.4/. Ideally I want to move the packages that are already installed in ~/.julia/v0.4 to the new location. But if that is not possible I can reinstall them.
What do I have to do?
Julia-v0.6 and before
one can change julia's package directory by following these steps:
run export JULIA_PKGDIR=/your/directory in shell(or manually add a new environment variable JULIA_PKGDIR on windows)
run Pkg.init() in julia to initialize a new package system
copy REQUIRE from old directory to the new one
run Pkg.resolve() in julia
Julia-v0.7+
The "Package directory" in the new package manager is called DEPOT_PATH, it can be changed by adding an environment variable JULIA_DEPOT_PATH:
JULIA_DEPOT_PATH=./test julia
julia> DEPOT_PATH
1-element Array{String,1}:
"./test"
(v0.7) pkg> add JSON2
Cloning default registries into /Users/gnimuc/test/registries
With the new package manager, we are able to create isolated projects in any directory we want instead of having a single giant package directory. Every project contains a Project.toml and a Manifest.toml if it has some dependencies. These two files record and keep tracking the environment of the project.
UPDATE
The following info might be obsoleted. I highly recommend to use PkgTemplates.jl for generating projects in Julia-v1.0+.
Generate a new project
We can generate a new project in any folder, but we must cd to the project folder to using the project. The (v0.7) below shows we're still in the default environment, so we cannot use the newly generated project:
(v0.7) pkg> generate ./MyNewProject
Generating project MyNewProject:
./MyNewProject/Project.toml
./MyNewProject/src/MyNewProject.jl
julia> using MyNewProject
ERROR: ArgumentError: Module MyNewProject not found in current path.
Run `Pkg.add("MyNewProject")` to install the MyNewProject package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:868
If we cd to the project folder and activate the environment, then we can using our new project without any problems:
shell> cd MyNewProject/
/Users/gnimuc/MyNewProject
(v0.7) pkg> activate .
(MyNewProject) pkg>
julia> using MyNewProject
I think that's the big difference between the new package manager and the old one. In short, we need to explicitly activate our unregistered project/package.
Download and init someone else's project
According to the doc, we can add an unregistered package/project via add command:
(HelloWorld) pkg> add https://github.com/fredrikekre/ImportMacros.jl
This command adds the target package as a dependency of our current project. In this example, we added ImportMacros in HelloWorld's Manifest.toml. What if we just use it as a top-level project? To add it to the default environment (v0.7)? no, we don't need to. The answer is we can directly download the code, cd to the folder and run instantiate in the pkg mode:
shell> git clone https://github.com/Gnimuc/GLTF.jl GLTF
Cloning into 'GLTF'...
remote: Counting objects: 286, done.
remote: Compressing objects: 100% (56/56), done.
remote: Total 286 (delta 73), reused 103 (delta 59), pack-reused 167
Receiving objects: 100% (286/286), 62.16 KiB | 46.00 KiB/s, done.
Resolving deltas: 100% (135/135), done.
shell> cd GLTF
pkg> activate .
(GLTF) pkg> instantiate
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
The new package manager is great! We neither need "include before using" nor make everything as a package just for using it. We have full-featured "Project" now!
Julia only way:
julia> ENV["JULIA_PKGDIR"] = "E:\\Julia-0.6.0\\portable"
"E:\\Julia-0.6.0\\portable"
julia> ENV["JULIA_PKGDIR"]
"E:\\Julia-0.6.0\\portable"
julia> Pkg.init()
INFO: Initializing package repository E:\Julia-0.6.0\portable\v0.6
INFO: Cloning METADATA from https://github.com/JuliaLang/METADATA.jl
However, the cache dir is still pointing to the old folder, so I checked why that is and figured it out:
julia> Base.LOAD_CACHE_PATH
1-element Array{String,1}:
"C:\\Users\\kung\\.julia\\lib\\v0.6"
julia> Pkg.__init__()
2-element Array{String,1}:
"E:\\Julia-0.6.0\\portable\\lib\\v0.6"
"C:\\Users\\kung\\.julia\\lib\\v0.6"
julia> pop!(Base.LOAD_CACHE_PATH)
"C:\\Users\\kung\\.julia\\lib\\v0.6"
julia> Base.LOAD_CACHE_PATH
1-element Array{String,1}:
"E:\\Julia-0.6.0\\portable\\lib\\v0.6"
As simple function:
function set_julia_dir(dir::String)
ENV["JULIA_PKGDIR"] = dir
Pkg.init()
Pkg.__init__()
pop!(Base.LOAD_CACHE_PATH)
end
set_julia_dir("E:\\Julia-0.6.0\\portable")
I want to deploy a basic trained R model as a webservice to AzureML. Similar to what is done here:
http://www.r-bloggers.com/deploying-a-car-price-model-using-r-and-azureml/
Since that post the publishWebService function in the R AzureML package was has changed it now requires me to have a workspace object as first parameter thus my R code looks as follows:
library(MASS)
library(AzureML)
PredictionModel = lm( medv ~ lstat , data = Boston )
PricePredFunktion = function(percent)
{return(predict(PredictionModel, data.frame(lstat =percent)))}
myWsID = "<my Workspace ID>"
myAuth = "<my Authorization code"
ws = workspace(myWsID, myAuth, api_endpoint = "https://studio.azureml.net/", .validate = TRUE)
# publish the R function to AzureML
PricePredService = publishWebService(
ws,
"PricePredFunktion",
"PricePredOnline",
list("lstat" = "float"),
list("mdev" = "float"),
myWsID,
myAuth
)
But every time I execute the code I get the following error:
Error in publishWebService(ws, "PricePredFunktion", "PricePredOnline", :
Requires external zip utility. Please install zip, ensure it's on your path and try again.
I tried installing programs that handle zip files (like 7zip) on my machine as well as calling the utils library in R which allows R to directly interact with zip files. But I couldn't get rid of the error.
I also found the R package code that is throwing the error, it is on line 154 on this page:
https://github.com/RevolutionAnalytics/AzureML/blob/master/R/internal.R
but it didn't help me in figuring out what to do.
Thanks in advance for any Help!
The Azure Machine Learning API requires the payload to be zipped, which is why the package insists on the zip utility being installed. (This is an unfortunate situation, and hopefully we can find a way in future to include a zip with the package.)
It is unlikely that you will ever encounter this situation on Linux, since most (all?) Linux distributions includes a zip utility.
Thus, on Windows, you have to do the following procedure once:
Install a zip utility (RTools has one and this works)
Ensure the zip is on your path
Restart R – this is important, otherwise R will not recognize the changed path
Upon completion, the litmus test is if R can see your zip. To do this, try:
Sys.which("zip")
You should get a result similar to this:
zip
"C:\\Rtools\\R-3.1\\bin\\zip.exe"
In other words, R should recognize the installation path.
On previous occasions when people told me this didn’t work, it was always because they thought they had a zip in the path, but it turned out they didn’t.
One last comment: installing 7zip may not work. The reason is that 7zip contains a utility called 7zip, but R will only look for a utility called zip.
I saw this link earlier but the additional clarification which made my code not work was
1. Address and Path of Rtools was not as straigt forward
2. You need to Reboot R
With regards to the address - always look where it was installed . I also used this code to set the path and ALWAYS ADD ZIP at the end
##Rtools.bin="C:\\Users\\User_2\\R-Portable\\Rtools\\bin"
Rtools.bin="C:\\Rtools\\bin\\zip"
sys.path = Sys.getenv("PATH")
if (Sys.which("zip") == "" ) {
system(paste("setx PATH \"", Rtools.bin, ";", sys.path, "\"", sep = ""))
}
Sys.which("zip")
you should get a return of
" C:\\RTools|\bin\zip"
From looking at Andrie's comment here: https://github.com/RevolutionAnalytics/AzureML/commit/9cf2c5c59f1f82b874dc7fdb1f9439b11ab60f40
Implies we can just download RTools and be done with it.
Download RTools from:
https://cran.r-project.org/bin/windows/Rtools/
During installation select the check box to modify the PATH
At first it didn't work. I then tried R32bit, and that seemed to work. Then R64 bit started working again. Honestly, not sure if I did something in the middle to make it work. Only takes a few minutes so worth a punt.
Try the following
-Download the Rtools file which usually contains the zip utility.
-Copy all the files in the "bin" folder of "Rtools"
-Paste them in "~/RStudio/bin/x64" folder
I want to use packrat on a Windows 7 machine with no internet connection.
I have downloaded all binary packages from http://cran.r-project.org/bin/windows/contrib/3.1/ into the local folder C:/xyz/CRAN_3_1.
The problem is now that
packrat::init(options=list(local.repos="C:/xyz/CRAN_3_1"))
throws a bunch of warnings and errors like
Warning: unable to access index for repository http://cran.rstudio/bin/...
Warning: unable to access index for repository http://cran.rstudio/src/...
Fetching sources for Rcpp (0.11.4) ... Failed
Package Rcpp not available in repository or locally
As it seems packrat tries to find
the binary version of Rcpp on CRAN (fails since there is no internet connection)
the source of Rcpp on CRAN (fails since there is no internet connection)
the local source of the package (fails since I only have the binaries)
What I don't understand is why packrat does not also search for the local binary package...
Question 1: I could download the source CRAN repository to get around this problem. But I would like to know from you guys whether there is an easier solution to this, i.e., whether it is possible to make packrat accept a local binary repo.
Question 2: When I create my own package myPackage with packrat enabled, will the myPackage-specific local packrat library also be included in the package? That is, assume that I give the binary myPackage zip File to one of my colleagues who does not have one of the packages that myPackage depends on (let's say Rcpp). Will Rcpp be included in myPackage when I use packrat? Or does my colleague have to install Rcpp himself?
I managed to hack around this problem. Please bear in mind that I have never used packrat before and that I do not know its "proper" behaviour. But my impression is that the hack works.
Here is how I did it:
Open your project, load packrat via library(packrat)
type fixInNamespace("snapshotImpl",ns="packrat") - a window opens - copy its content into the clipboard
Go to /yourProjDir/ and create a file snapshotImplFix.R
Copy the clipboard's content into this file ...
... but change the first line to
snapshotImplFix=function (project, available = NULL, lib.loc = libDir(project),
dry.run = FALSE, ignore.stale = FALSE, prompt = interactive(),
auto.snapshot = FALSE, verbose = TRUE, fallback.ok = FALSE,
snapshot.sources = FALSE)
Note snapshot.sources = FALSE! Save and close the file.
Create /yourProjDir/.Rprofile and add
setHook(packageEvent("packrat","onLoad"),function(...) {
source("./snapshotImplFix.R");
tmpfun=get("snapshotImpl",envir=asNamespace("packrat"));
environment(snapshotImplFix)=environment(tmpfun);
utils::assignInNamespace(x="snapshotImpl",value=snapshotImplFix,ns="packrat");})
Points 2-6 fix the problem with the snapshot.sources argument being TRUE by default (I did not find a better way to change that...)
Finally, we have to tell packrat to take our local repository. It's important that you have the right folder structure. Therefore I moved the repo from C:/xyz/CRAN_3_1 to C:/xyz/CRAN_3_1/bin/windows/contrib/3.1. Do not forget to run library(tools);write_PACKAGES("C:/xyz/CRAN_3_1/bin/windows/contrib/3.1"); if you also have to move your files.
Open yourProjDir/.Rprofile again and add at the end
local({r=getOption("repos");r["CRAN"]="file:///C:/xyz/CRAN_3_1";r["CRANextra"]=r["CRAN"];options(repos=r)})
Note the 3 / right after file! Save and exit file.
Close the project and re-open.
Now you can execute packrat::init() and it should run without errors.
It would be great if someone with more experience regarding packrat could give his/her input so that I can be sure that this hack works. Any pointers to proper solutions are highly appreciated, of course.
I'm using Qt to develop a Symbian app.
I downloaded qjson from the link. I followed the instructions in that link and yes, I have the qjson.sis file. Now I need to use it in my app. When I tried, I got this error.
Launch failed: Command answer [command error], 1 values(s) to request: 'C|101|Processes|start|""|"MyProject.exe"|[""]|[]|true'
{"Code":-46,Format="Failed to create the process (verify that the executable and all required DLLs have been transferred) (permission denied)"}
Error: 'Failed to create the process (verify that the executable and all required DLLs have been transferred) (permission denied)' Code: -46
And when I press the launch icon, it shows, "Unable to execute file for security reasons".
Then I install the qjson.sis in my mobile and then tried to install my app, I got this error.
:-1: error: Installation failed: 'Failed to overwrite file owned by another package: c:\sys\bin\qjson.dll in ' Code: 131073; see http://wiki.forum.nokia.com/index.php/Symbian_OS_Error_Codes for descriptions of the error codes
In my .pro file I have this.
symbian: {
addFiles.sources = qjson.dll
addFiles.path = /sys/bin
DEPLOYMENT += addFiles
}
symbian: {
LIBS += -lqjson
}
Any ideas...?
Ok, I've just resolved a similar issue: it seems that your current build of QJson's library has different UID3 than the previous one that you installed on the phone.
Each .SIS file that is installed on the device has an identifier. The phone OS tracks which file was installed by which packacge, and if some new package wants to overwrite an existing file, the OS checks whether the new package has the same 'identity' than the previous owner of the file to be overwritten.
If the identity does not match, this error pops up.
There are number of reasons why this could have happened. For example, you could have simply changed the UID3 of the QJson before the build. Or, maybe you have forgot to set the library's UID3? Check the "src.pro' in the QJson project and go to the half of the file, you'd see lines:
#TARGET.UID3 =
TARGET.CAPABILITY = ReadDeviceData WriteDeviceData
If there's #, then you have forgot to set it and the build process assumed, well, letssay 'a random value'. So, now, set it to something, ie. TARGET.UID3 = 0xE0123456. Remember to correct that once you are ready to publish the application.
If a package with broken UID3 gets onto your phone and is blocking something - simply: uninstall it. Go to Settings/Installations/Installed, then find "qjson" and uninstall it. Afterwards, next installtion of qjson should succeed with no problems.