Questions tagged [labelled-generic]

14 questions
24
votes
2 answers

Shapeless - turn a case class into another with fields in different order

I'm thinking of doing something similar to Safely copying fields between case classes of different types but with reordered fields, i.e. case class A(foo: Int, bar: Int) case class B(bar: Int, foo: Int) And I'd like to have something to turn a A(3,…
Utaal
  • 8,044
  • 4
  • 25
  • 37
19
votes
1 answer

Extract label values from a LabelledGeneric instance

Consider the following example: import shapeless._ case class Foo(bar: String, baz: Boolean) val labl = LabelledGeneric[Foo] Now, the type of labl is (prettified) LabelledGeneric[Foo] { type Repr = FieldType[Symbol @@ String("bar"), String]…
Gabriele Petronella
  • 102,227
  • 20
  • 204
  • 227
8
votes
1 answer

Using shapeless tags with LabelledGenerics

Suppose I'd like to traverse case class generic representation as described here I've defined some typeclass to describe fields: trait Described[X] extends (X => String) object Described{ def apply[X](x: X)(implicit desc: Described[X]) =…
Odomontois
  • 14,820
  • 2
  • 34
  • 67
8
votes
1 answer

Pass a type parameter to be used as argument LabelledGeneric

I'm trying to parametrize a method that needs to work on a generic type A for which a LabelledGeneric can be retrieved. Here's the naive approach case class Foo(bar: String, baz: Boolean) def params[A](a: A) = { val lbl = LabelledGeneric[A] val…
Gabriele Petronella
  • 102,227
  • 20
  • 204
  • 227
4
votes
1 answer

Shapeless align with different types but same labels

Does someone know how to align two records when they have the same name of fields but not the same values one has values wrapped in Column another one wrapped in Option and I need to align them as the order is different import shapeless._ import…
user1698641
  • 211
  • 1
  • 11
3
votes
3 answers

Generically morph a class into another using Shapeless + LabelledGenerics

I know using Shapeless I can do something like this: import shapeless._, syntax.singleton._, record._ case class Foo(x: Int, y: String) case class RichFoo(x: Int, y: String, z: Double) def makeRich(foo: Foo): RichFoo = { val x = ('z…
pathikrit
  • 29,060
  • 33
  • 127
  • 206
2
votes
1 answer

shapeless Mapper for LabelledGeneric not found

I have basic type pool defined like that: sealed trait Section final case class Header(...) extends Section final case class Customer(...) extends Section final case class Supplier(...) extends Section final case class Tech(...) extends Section I'd…
Odomontois
  • 14,820
  • 2
  • 34
  • 67
1
vote
1 answer

"Error: Can't convert to character"

My student and I both loaded the same dataset, installed the same packages, and were running the same code. When I run "frq" I get a frequency table and the variable is labeled as "numeric." When my student runs the same code, she gets "Error: Can't…
mt646
  • 11
  • 1
0
votes
1 answer

Assign variable labels in loop

I've got a big old dataset that I would like to programmatically label. To do so I've used the look_for() function from the labelled package to create a df of variables and labels, which I want to loop through to assign labels to my variables. Below…
Francisco
  • 105
  • 9
0
votes
0 answers

How to keep vectors as "labelled" when merging data frames with merge or left_join?

I am merging data frames, one of which has labelled data. However, when the data frames merge the labelled vectors become numeric. How could I keep this from happening? The following example shows the problem with…
0
votes
1 answer

could not find implicit value for shapeless.ops.record.Selector

I am playing around with shapeless to explore the possibility of extracting the value type in a shapeless labeled record. The motivation is that I can then use type classes and implicits to dispatch the process flow based on the type. However, the…
codeFun
  • 41
  • 3
0
votes
0 answers

Error expression using label_parsed in facet_grid

It seems that label_parsed function does not work to show an expression for labels of figures in facet_grid (see the figure bellow). data file is here I expected that CO2 will show with subscript for 2. It did not and returned an error when I…
QVN
  • 9
  • 3
0
votes
1 answer

Witness type derivation issue

I want to build general solution for field removing from case classes. Using this trick I built this working code: implicit class SemiGenericIgnoringOps[T](t: T) { def ignoring[TRepr <: HList, V, …
St.
  • 509
  • 3
  • 8
0
votes
0 answers

Get field names and values from LablelledGenerics of a case class

I try to have Seq[String], containing the fields name of a case class And another Seq[String] containing values of case class. In a generic way. I think I will have to map values with a Poly1 function to have the Arbitrary type => String. But now,…
crak
  • 1,398
  • 1
  • 14
  • 30