-1

The code is as below:

schema = schema(`Key`=int64(),
                 Sex = string(),
                `Age` = int64(),
                `Date of Birth` = date32(),
                `Institution` = string(),
                `Admission Date` = date32(),
                `Discharge Date` = date32(),
                `Elderly Home` = string(),
                `Paycode` = string())

class(schema)

R returns:

Error in `check_schema()`:
! `schema` must be an object of class 'Schema' not 'list'.
Run `rlang::last_error()` to see where the error occurred.

> class(schema)
[1] "list"

Is it possible to convert the list into schema? enter image description here

enter image description here

The version that I run : The version should be Arrow package version: 11.0.0.2.

> arrow::arrow_info()
Arrow package version: 11.0.0.2

Arrow options():
                       
arrow.use_threads FALSE
doraemon
  • 439
  • 3
  • 10

2 Answers2

2

I can't reproduce the error you are describing, but we can turn a list object into a schema by using rlang::inject():

library(arrow)

schema_ls <- list(
     `Key`=int64(),
     Sex = string(),
     `Age` = int64(),
     `Date of Birth` = date32(),
     `Institution` = string(),
     `Admission Date` = date32(),
     `Discharge Date` = date32(),
     `Elderly Home` = string(),
     `Paycode` = string())


rlang::inject(schema(!!!schema_ls))
#> Schema
#> Key: int64
#> Sex: string
#> Age: int64
#> Date of Birth: date32[day]
#> Institution: string
#> Admission Date: date32[day]
#> Discharge Date: date32[day]
#> Elderly Home: string
#> Paycode: string

Regarding the error shown in the OP, below is what I'm seeing:

library(arrow)

schema = schema(`Key`=int64(),
                Sex = string(),
                `Age` = int64(),
                `Date of Birth` = date32(),
                `Institution` = string(),
                `Admission Date` = date32(),
                `Discharge Date` = date32(),
                `Elderly Home` = string(),
                `Paycode` = string())
class(schema)
#> [1] "Schema"      "ArrowObject" "R6"

Created on 2023-03-23 with reprex v2.0.2

TimTeaFan
  • 17,549
  • 4
  • 18
  • 39
  • Still cannot work, the result is updated – doraemon Mar 23 '23 at 09:45
  • To better understand what error you are seeing and where it is coming from, we would need an reproducible example, probably with some data, and the function calls your are making. – TimTeaFan Mar 23 '23 at 09:55
  • I just run the code that I provided... – doraemon Mar 23 '23 at 09:59
  • 2
    @doraemon: If I run your code everything is working as expected (see updated answer). You could try: i) restarting your R session, 2) loading only the 'arrow' package and run the code again. If you still get arrows, let us know which version of arrow you are using. – TimTeaFan Mar 23 '23 at 10:04
  • 1
    As others have said, the package version would help. You can run `arrow::arrow_info()` to get information about the arrow package version. – thisisnic Mar 23 '23 at 10:59
  • `check_schema` was [introduced in arrow-11.0.0.2](https://github.com/cran/arrow/blame/b0f53c5217835ed8365fd0c8070ae784065a9d2b/R/dataset-format.R#L300) (no changelog listing yet), so it seems likely to be either 11.0.0.2 or 11.0.0.3 (current) (or dev?). – r2evans Mar 23 '23 at 12:12
  • @r2evans: I'm using version 11.0.0.3. – TimTeaFan Mar 23 '23 at 12:14
  • @doraemon what version are you running? It's been requested a few times ... – r2evans Mar 23 '23 at 12:22
  • `check_schema()` is an internal function used for checking that everything lines up when someone is using `open_dataset()` and provides both a schema and column names. It isn't exported from the package, and isn't intended to be used in other contexts. – thisisnic Mar 23 '23 at 13:02
  • Sorry for late reply. I had something to work last night... The version that I run is updated. Thank you! – doraemon Mar 24 '23 at 01:30
0

The reason why arrow::schema not work is that:

> library(plotly)

Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

    last_plot

The following object is masked from ‘package:arrow’:

    schema

The following object is masked from ‘package:stats’:

    filter

The following object is masked from ‘package:graphics’:

    layout

Therefore, the arrow::schema function cannot be correctly executed.

doraemon
  • 439
  • 3
  • 10