Re: [R-SIG-Mac] pasting from the clipboard

2018-10-09 Thread Timothy Bates
For what it’s worth, this is the function I use:

umx::umx_write_to_clipboard <- function (x) {
if (umx_check_OS("OSX")) {
clipboard <- pipe("pbcopy", "w")
write.table(x, file = clipboard, sep = "\t", row.names = FALSE, 
col.names = FALSE, quote = FALSE)
close(clipboard)
}
else if (umx_check_OS("Windows")) {
write.table(x, file = "clipboard", sep = "\t", col.names = NA)
}
else {
message("clipboard not implemented for *nix - awaiting a reliable 
solution. 
See:\n\t\thttps://stackoverflow.com/questions/13438556/how-do-i-copy-and-paste-data-into-r-from-the-clipboard#13438558;)
}
}


Checking for updates on the unix front, I see a package called datapasta 
https://CRAN.R-project.org/package=datapasta 


Not sure how good it is




> On 8 Oct 2018, at 10:08, peter dalgaard  wrote:
> read.table(text=my_str,) saves you the dangling open connection.
> -pd
>> On 8 Oct 2018, at 02:43 , Tom Hopper  wrote:
>> 
>> Another approach that should work cross-platform is to paste the data into
>> a string, then read the string using read.table():
>> 
>> my_str <- ""
>> my_df <- read.table(textConnection(object = my_str),
>>   header = TRUE,
>>   sep = "",
>>   stringsAsFactors = FALSE)
>> 
>> The pasted data should have line breaks so each row is on its own line in
>> your script, and you'll want to adjust the parameters header and sep to
>> suit your data.
>> 
>> An example of suitable data would be:
>> 
>> my_str <- "T_/K Density_g/mL D2O
>> 273 0.999841 1.10469
>> 274 0.00 NA
>> 275 0.41 NA"
>> 
 On Oct 3, 2018, at 9:22 AM, Robert Baer  wrote:
 My memory is that  on the Mac
 
 dat = read.table(file = pipe("pbpaste"), header = TRUE)  # should
>>> allow me to paste a dataframe copied from a spreadsheet into R.
 
 When I try that in RStudio 1.1.456 with R 3.5.1 on OSX 10.13.1
 
 I get the message:
 
 incomplete line found by readTableHeader on 'pbpaste'
 
 Could anyone explain this message to me,  and more importantly, tell me
>>> the proper way to paste a dataframe copied to the clipboard from Excel on
>>> the Mac?
 
>>> The default cell (field) delimiter with Excel is the TAB character, so you
>>> want to use something like:
>>> 
>>> read.table(pipe("pbpaste"), sep = "\t", header = TRUE)
>>> 
>>> Note that you will likely get a warning along the lines of what you got
>>> above, which I believe is due to Excel not having an EOL for the final row
>>> in the clipboard.
>>> 
>>> Regards, Marc Schwartz

[[alternative HTML version deleted]]

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] pasting from the clipboard

2018-10-08 Thread peter dalgaard
read.table(text=my_str,) saves you the dangling open connection.

-pd

> On 8 Oct 2018, at 02:43 , Tom Hopper  wrote:
> 
> Another approach that should work cross-platform is to paste the data into
> a string, then read the string using read.table():
> 
> my_str <- ""
> my_df <- read.table(textConnection(object = my_str),
>header = TRUE,
>sep = "",
>stringsAsFactors = FALSE)
> 
> The pasted data should have line breaks so each row is on its own line in
> your script, and you'll want to adjust the parameters header and sep to
> suit your data.
> 
> An example of suitable data would be:
> 
> my_str <- "T_/K Density_g/mL D2O
> 273 0.999841 1.10469
> 274 0.00 NA
> 275 0.41 NA"
> 
> Regards,
> 
> Tom
> 
> On Wed, Oct 3, 2018 at 10:10 AM Marc Schwartz via R-SIG-Mac <
> r-sig-mac@r-project.org> wrote:
> 
>> 
>>> On Oct 3, 2018, at 9:22 AM, Robert Baer  wrote:
>>> 
>>> My memory is that  on the Mac
>>> 
>>> dat = read.table(file = pipe("pbpaste"), header = TRUE)  # should
>> allow me to paste a dataframe copied from a spreadsheet into R.
>>> 
>>> When I try that in RStudio 1.1.456 with R 3.5.1 on OSX 10.13.1
>>> 
>>> I get the message:
>>> 
>>>  incomplete line found by readTableHeader on 'pbpaste'
>>> 
>>> Could anyone explain this message to me,  and more importantly, tell me
>> the proper way to paste a dataframe copied to the clipboard from Excel on
>> the Mac?
>>> 
>>> 
>> 
>> 
>> Hi,
>> 
>> The default cell (field) delimiter with Excel is the TAB character, so you
>> want to use something like:
>> 
>>  read.table(pipe("pbpaste"), sep = "\t", header = TRUE)
>> 
>> Note that you will likely get a warning along the lines of what you got
>> above, which I believe is due to Excel not having an EOL for the final row
>> in the clipboard.
>> 
>> Regards,
>> 
>> Marc Schwartz
>> 
>> 
>> 
>> 
>>[[alternative HTML version deleted]]
>> 
>> ___
>> R-SIG-Mac mailing list
>> R-SIG-Mac@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>> 
> 
>   [[alternative HTML version deleted]]
> 
> ___
> R-SIG-Mac mailing list
> R-SIG-Mac@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] pasting from the clipboard

2018-10-07 Thread Tom Hopper
Another approach that should work cross-platform is to paste the data into
a string, then read the string using read.table():

my_str <- ""
my_df <- read.table(textConnection(object = my_str),
header = TRUE,
sep = "",
stringsAsFactors = FALSE)

The pasted data should have line breaks so each row is on its own line in
your script, and you'll want to adjust the parameters header and sep to
suit your data.

An example of suitable data would be:

my_str <- "T_/K Density_g/mL D2O
273 0.999841 1.10469
274 0.00 NA
275 0.41 NA"

Regards,

Tom

On Wed, Oct 3, 2018 at 10:10 AM Marc Schwartz via R-SIG-Mac <
r-sig-mac@r-project.org> wrote:

>
> > On Oct 3, 2018, at 9:22 AM, Robert Baer  wrote:
> >
> > My memory is that  on the Mac
> >
> > dat = read.table(file = pipe("pbpaste"), header = TRUE)  # should
> allow me to paste a dataframe copied from a spreadsheet into R.
> >
> > When I try that in RStudio 1.1.456 with R 3.5.1 on OSX 10.13.1
> >
> > I get the message:
> >
> >   incomplete line found by readTableHeader on 'pbpaste'
> >
> > Could anyone explain this message to me,  and more importantly, tell me
> the proper way to paste a dataframe copied to the clipboard from Excel on
> the Mac?
> >
> >
>
>
> Hi,
>
> The default cell (field) delimiter with Excel is the TAB character, so you
> want to use something like:
>
>   read.table(pipe("pbpaste"), sep = "\t", header = TRUE)
>
> Note that you will likely get a warning along the lines of what you got
> above, which I believe is due to Excel not having an EOL for the final row
> in the clipboard.
>
> Regards,
>
> Marc Schwartz
>
>
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-SIG-Mac mailing list
> R-SIG-Mac@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>

[[alternative HTML version deleted]]

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


[R-SIG-Mac] pasting from the clipboard

2018-10-03 Thread Robert Baer

My memory is that  on the Mac

dat = read.table(file = pipe("pbpaste"), header = TRUE)  # should 
allow me to paste a dataframe copied from a spreadsheet into R.


When I try that in RStudio 1.1.456 with R 3.5.1 on OSX 10.13.1

I get the message:

  incomplete line found by readTableHeader on 'pbpaste'

Could anyone explain this message to me,  and more importantly, tell me 
the proper way to paste a dataframe copied to the clipboard from Excel 
on the Mac?



--


--
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A T Still University of Health Sciences
800 W. Jefferson St
Kirksville, MO 63501
660-626-2321 Department
660-626-2965 FAX

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac