Problem using r_data_frame/3 with lists

23 views
Skip to first unread message

Franco Masotti

unread,
Nov 22, 2016, 1:53:41 PM11/22/16
to SWI-Prolog
Hello,

my situation is the following: I have two sets of data (X and Y) stored in a list and
the following predicates:

xy_from_list(L,X,Y) which leads to: X = [a list of length n], Y = [a list of length n]

[...]
r_data_frame(df, [x=X,y=Y], xy_from_list(L,X,Y)),
<- ggplot(data=df,aes(x=x,y=y,group=1)) + geom_line() + geom_point().

I get:
    r_assign_/3 Type error: 'bool' expected, found [...] (a list)

I followed the example from the documentation (the one with sin(360,X,Y)) but that predicate doesn't use lists.

Do you have any ideas to transform X and Y in a format compatible to r_data_frame/3 ?

Thanks in advance.

nicos.ang...@gmail.com

unread,
Nov 22, 2016, 5:37:06 PM11/22/16
to SWI-Prolog

Dear Franco,

I am not familiar with Rserve_client but a quick look at the sources shows that
there is a findall involved in collecting the lists. So your xy_from_list(L,X,Y)
should return one element for X and one for Y at each success- not the whole lists.

Alternatively you can modify xy_from_list( L, XY ) where XY is a list of 2 arity terms
something like [r(x1,y1),r(x2,y2),...,r(xn,yn)]  and then call r_data_frame_from_rows/2.

Hope it helps,

Nicos Angelopoulos
---
http://stoics.org.uk/~nicos

Franco Masotti

unread,
Nov 22, 2016, 6:12:09 PM11/22/16
to SWI-Prolog
Hello Nicos,

Yes, what you're saying is correct. I've opted for the first solution, that is
using member/2 to return element by element.
Now I have to study cuts and negations (chaper 10 - LPN)
in order to avoid all extra answers.

Thanks a lot.

Jan Wielemaker

unread,
Nov 23, 2016, 3:38:13 PM11/23/16
to Franco Masotti, SWI-Prolog
On 11/23/2016 12:12 AM, Franco Masotti wrote:
> Hello Nicos,
>
> Yes, what you're saying is correct. I've opted for the first solution,
> that is
> using member/2 to return element by element.
> Now I have to study cuts and negations (chaper 10 - LPN)
> in order to avoid all extra answers.

The idea behind r_data_frame/3 is to turn the implicit table
behind the solutions of a goal into an R data frame. The
idea behind that is that you have a dataset loaded as RDF or
plain Prolog, you define some relation r(X,Y,...) over it and
than use r_data_frame/3 to generate an R version of the
r/n relation as a data set and use R processing on that.

Cheers --- Jan

Franco Masotti

unread,
Nov 24, 2016, 2:22:45 PM11/24/16
to SWI-Prolog, franco....@student.unife.it

Thanks Jan,
I'll work on that.

Cheers.
Reply all
Reply to author
Forward
0 new messages