Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when plot_nn #145

Open
jolundgren opened this issue Feb 11, 2015 · 11 comments
Open

Error when plot_nn #145

jolundgren opened this issue Feb 11, 2015 · 11 comments
Labels
Type: Bug Something is broken!

Comments

@jolundgren
Copy link

Get's an error message while using R.plot_nn

Replicated the script from the blog "F# Neural Networks with RProvider & Deedle" so I excluded any misstaket on my side.

Using latest RProvider.1.1.8

Error in neuralnet::plot.nn(x = fsr_2936_27, rep = fsr_2936_28) :
could not find function "grid.newpage"
RDotNet.EvaluationException: Error in neuralnet::plot.nn(x = fsr_2936_27, rep = fsr_2936_28) :
could not find function "grid.newpage"

at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement)
at RDotNet.REngine.d__0.MoveNext()
at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
at RDotNet.REngine.Evaluate(String statement)
at <StartupCode$FSI_0010>.$FSI_0010.main@()
Stopped due to error

@tpetricek
Copy link
Member

Can you share a minimal repro that gives this error? Or perhaps @sergey-tihon would know?

@jolundgren
Copy link
Author

Yes, this is code from his blog that I changed just a little because Species (Iris data) could not be strings so I converted them to ints thats all.

#load "packages/Deedle.1.1.0-beta/Deedle.fsx"
#load "packages/RProvider.1.1.8/RProvider.fsx"

open RProvider.utils
//R.install_packages("nuralnet")
//R.install_packages("caret")
//R.install_packages("gridExtra")
open Deedle
open RDotNet
open RProvider
open RProvider.base
open RProvider.datasets
open RProvider.neuralnet
open RProvider.caret
open RProvider.graphics
open RProvider.grid
open RProvider.ggplot2

let test x =
match x with
| "setosa" -> "1"
| "versicolor" -> "2"
| "virginica" -> "3"
| a -> "0"

let iris : Frame<int, string> = R.iris.GetValue()

let features =
iris
|> Frame.filterCols (fun c _ -> c <> "Species")
|> Frame.mapColValues (fun c -> c.As())

let helper = iris.Columns.["Species"].As() |> Series.map(fun x y -> test y)

iris.DropColumn("Species")

iris?Species <- helper
let targets =
R.as_factor(iris.Columns.["Species"].As())

let ir = iris |> Frame.mapColValues (fun c -> c.As())

//R.featurePlot(x = features, y = targets, plot = "pairs")

let range = [1..iris.RowCount]
let trainingIdxs : int[] = R.sample(range, ir.RowCount*7/10).GetValue()
let testingIdxs : int[] = R.setdiff(range, trainingIdxs).GetValue()
let trainingSet = ir.Rows.[trainingIdxs]
let testingSet = ir.Rows.[testingIdxs]

let nn =
R.neuralnet(
"Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width",
data = trainingSet, hidden = R.c(3,2),
err_fct = "sse", linear_output = true)

R.plot_nn(nn, rep="best")

@tpetricek
Copy link
Member

It would be very helpful if you found the single line that causes the issue and created just a few line snippet that we can use to diagnose what is going wrong.

@tpetricek tpetricek added the Type: Bug Something is broken! label Feb 11, 2015
@jolundgren
Copy link
Author

It is the last line:

R.plot_nn(nn, rep="best")

@jolundgren
Copy link
Author

R x64 3.0.2

2015-02-11 22:26 GMT+01:00 Sergey Tihon [email protected]:

@jolundgren https://github.com/jolundgren What version of R do you use?


Reply to this email directly or view it on GitHub
#145 (comment)
.

@sergey-tihon
Copy link
Contributor

Found in the log

[4/9/2015 1:01:00 AM] [Pid:12988, Tid:1, Apid:1] eval(neuralnet::`plot.nn`(x=fsr_12988_44))
[4/9/2015 1:01:00 AM] [Pid:12988, Tid:1, Apid:1] Output: Error in plot.nn(net, rep = i, x.entry, x.out, radius, arrow.length, intercept,  : 
  could not find function "grid.newpage"
In addition: Warning message:
package 'grid' is not available (as a binary package for R version 3.1.3) 

[4/9/2015 1:01:00 AM] [Pid:12988, Tid:1, Apid:1] Operation failed:
  RDotNet.EvaluationException: Error in plot.nn(net, rep = i, x.entry, x.out, radius, arrow.length, intercept,  : 
  could not find function "grid.newpage"

   at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement)
   at RDotNet.REngine.<Defer>d__0.MoveNext()
   at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
   at RDotNet.REngine.Evaluate(String statement)
   at RProvider.Internal.Logging.logWithOutput[a](CharacterDeviceInterceptor characterDevice, FSharpFunc`2 f) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\Logging.fs:line 57

I see package 'grid' is not available (as a binary package for R version 3.1.3) line but package is installed

@sergey-tihon
Copy link
Contributor

A bit more light on the problem:
neuralnet package has a dependency on grid package details see here
but grid packages were removed from CRAN repository and included in distributive of R

@luminescent
Copy link

Some extra information that might be helpful: I also have this error with R 3.1.1 although the R console can find the package grid and also access grid.newpage without issues. The function is not found only when called from the type provider, in FSI.
Even more, the intellisense in Visual Studio can find the function grid.newpage, but it uses the underscore instead of ., so it is R.grid_newpage.

And strangely the same error is displayed when using graphics.plot. So I added this code:

open RProvider.graphics
R.plot nn 

but nothing changed. Again this works fine in the R console.

@tpetricek
Copy link
Member

I wonder if this is related to the error reported here (also #121).

Can you try adding:

R.eval(R.parse(text="library(grid)"))

Or perhaps:

R.eval(R.parse(text="library(neuralnet)"))

And see if this makes it work? (The R provider should do this automatically, but it looks like there might be some corner case...)

@sergey-tihon
Copy link
Contributor

You are right. It helps:

R.eval(R.parse(text="library(grid)"))

@laygr
Copy link

laygr commented Feb 3, 2017

This was happening to me but with the package fArma. The same solution applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something is broken!
Projects
None yet
Development

No branches or pull requests

5 participants