ropensci / redland-bindings

Redland librdf language bindings
http://librdf.org/bindings/
Other
17 stars 3 forks source link

serializeToFile has no signature for `connection` (e.g. stdout()) #63

Open cboettig opened 6 years ago

cboettig commented 6 years ago

As suggested by @amoeba : would be nice to serialize to stdout() instead of a literal file path, but this throws an error

  unable to find an inherited method for function ‘serializeToFile’ for signature ‘"Serializer", "World", "Model", "terminal"’ 
cboettig commented 6 years ago

Or maybe I should just be using serializeToCharacter here?

gothub commented 6 years ago

@cboettig the Serialize class is maybe following the redland C library to closely here, and it would have been better to make a serialize method that was more R friendly. As we currently have serializeToCharacter and serializeToFile, where does it make the most sense to put in support for writing to a connection? Maybe

serialize(serializer, world, model, con=stdout())

which is similar to

writeLines(text, con = stdout(), sep = "\n", useBytes = FALSE)

where con is handled in this way:

If the con is a character string, the function calls file to obtain a file connection which is opened for the duration of the function call.

If the connection is open it is written from its current position. If it is not open, it is opened for the duration of the call in "wt" mode and then closed again.