0

I am writing a package that would create a CSV gists on github.com from a data frame. Signature would be like so:

gist.csv(my.data.frame, public=FALSE, description="my results in CSV")

I'm using httr for the HTTP calls and the GitHub API expects the content of the gist as part of the body.

However, I'm stuck on serialising the object my.data.frame into a CSV string and assigning the string into a variable. I'm looking for a way to have

csv.string <- write.csv(my.data.table)

Is there a good way to achieve that (ideally without having to resolve to writing to a temp file)

1 Answer 1

2

You can write to a variable in R via a textConnection. For example

#sample data
dd <- data.frame(x=1:10, y=letters[1:10])

#write to variable
x <- ""
tx <- textConnection("x","w")
write.csv(dd, tx)
close(tx)

#check contents
cat(x, sep="\n")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.