4

I am having 2 R sessions now working on one vector in each of the session with slight difference inside, say:

session1: temp1 <- c(1:10)

session2: temp2 <- c(2:11)

I want to copy the temp1 from session1 into session2 and do a %in%, but I don't want use print(temp1) in session1, ctrl-c it, manually modify the output and then ctrl-v it in session2.

I have seen someone using a generic function that create an output in the R session, then I ctrl-c the output directly and ctrl-v it in another R session and the object is already there. But I can't remember the function.

Thanks.

lokheart
  • 23,743
  • 39
  • 98
  • 169

1 Answers1

7

You will have to pass the data from one session to another. That means you need to (efficiently) serialize the data.

The easiest, by far, will be a save() followed by a load(). If you want to be fancy, you can use sockets instead of files -- see help(connections) for details

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • yea, I know this is possible but isn't there a function that (something like `cat` an object into a bunch of lines) directly copy-paste the output to another session will give you back the object? I saw it somewhere in stackoverflow but forget it, so wondering if anyone knows – lokheart Oct 16 '12 at 02:51
  • 3
    `dput` is the function your comment is looking for, but that that is not what your question appears to be asking – mnel Oct 16 '12 at 02:54
  • 1
    Yes -- `dput()` works well for tiny objects. But one day you will want to pass _real_ data around for which the _serialization to printable ascii_ is way too inefficient. Enter `save()` / `load()`. – Dirk Eddelbuettel Oct 16 '12 at 02:56
  • yea, I won't use `dput` for a big dataframe, just a vector with maybe 100 strings. – lokheart Oct 16 '12 at 02:57