how do I reprex reproduce a data frame in R?
I sometimes have to copy data from Excel into R. The workflow goes something like this:
# Step 1: Highlight Excel spreadsheet to be copied into R
# Step 2: Run this command to get the data into R
excelss <- read.delim("clipboard") # for Windows
If I print(excelss)
I get my data frame
Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53
The question is: How do I take this data frame output, and permanently save it in my script? What reprex commands do I use? So that the next time I open the script the data frame will be right there, and I don't have to open Excel and go through the whole copy/paste routine again?
Or another way to put it. How do I take console data frame output and save it to my editor?
r reproducible-research reprex
add a comment |
I sometimes have to copy data from Excel into R. The workflow goes something like this:
# Step 1: Highlight Excel spreadsheet to be copied into R
# Step 2: Run this command to get the data into R
excelss <- read.delim("clipboard") # for Windows
If I print(excelss)
I get my data frame
Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53
The question is: How do I take this data frame output, and permanently save it in my script? What reprex commands do I use? So that the next time I open the script the data frame will be right there, and I don't have to open Excel and go through the whole copy/paste routine again?
Or another way to put it. How do I take console data frame output and save it to my editor?
r reproducible-research reprex
Useread.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters besidetext=
are set as inread.delim()
Usually I useread.table(header=TRUE, text="...")
– jogo
Nov 21 '18 at 13:03
Why can't you usereadxl::read_excel()
? Copy/paste does not lend itself to reproducible workflows (nor does it facilitate eventual automation/scripting).
– hrbrmstr
Nov 21 '18 at 13:14
@hrbrmstr for my case I want the data directly in the script and don't want to have to reference the excel file the data originally came from or load any packages on top of base-R. I work with sensitive data and the Excel file (and that workflow you mention) causes issues with security (if I can leave it at that).
– stackinator
Nov 21 '18 at 13:19
@jogo can you put that in the answer format? I can't quite follow what you mean. Istext="..."
shorthand for copy your console output to this space? I tried that but the row numbers the console print screws everything up. Thanks
– stackinator
Nov 21 '18 at 13:39
add a comment |
I sometimes have to copy data from Excel into R. The workflow goes something like this:
# Step 1: Highlight Excel spreadsheet to be copied into R
# Step 2: Run this command to get the data into R
excelss <- read.delim("clipboard") # for Windows
If I print(excelss)
I get my data frame
Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53
The question is: How do I take this data frame output, and permanently save it in my script? What reprex commands do I use? So that the next time I open the script the data frame will be right there, and I don't have to open Excel and go through the whole copy/paste routine again?
Or another way to put it. How do I take console data frame output and save it to my editor?
r reproducible-research reprex
I sometimes have to copy data from Excel into R. The workflow goes something like this:
# Step 1: Highlight Excel spreadsheet to be copied into R
# Step 2: Run this command to get the data into R
excelss <- read.delim("clipboard") # for Windows
If I print(excelss)
I get my data frame
Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53
The question is: How do I take this data frame output, and permanently save it in my script? What reprex commands do I use? So that the next time I open the script the data frame will be right there, and I don't have to open Excel and go through the whole copy/paste routine again?
Or another way to put it. How do I take console data frame output and save it to my editor?
r reproducible-research reprex
r reproducible-research reprex
edited Nov 21 '18 at 13:35
stackinator
asked Nov 21 '18 at 13:00
stackinatorstackinator
1,2891519
1,2891519
Useread.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters besidetext=
are set as inread.delim()
Usually I useread.table(header=TRUE, text="...")
– jogo
Nov 21 '18 at 13:03
Why can't you usereadxl::read_excel()
? Copy/paste does not lend itself to reproducible workflows (nor does it facilitate eventual automation/scripting).
– hrbrmstr
Nov 21 '18 at 13:14
@hrbrmstr for my case I want the data directly in the script and don't want to have to reference the excel file the data originally came from or load any packages on top of base-R. I work with sensitive data and the Excel file (and that workflow you mention) causes issues with security (if I can leave it at that).
– stackinator
Nov 21 '18 at 13:19
@jogo can you put that in the answer format? I can't quite follow what you mean. Istext="..."
shorthand for copy your console output to this space? I tried that but the row numbers the console print screws everything up. Thanks
– stackinator
Nov 21 '18 at 13:39
add a comment |
Useread.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters besidetext=
are set as inread.delim()
Usually I useread.table(header=TRUE, text="...")
– jogo
Nov 21 '18 at 13:03
Why can't you usereadxl::read_excel()
? Copy/paste does not lend itself to reproducible workflows (nor does it facilitate eventual automation/scripting).
– hrbrmstr
Nov 21 '18 at 13:14
@hrbrmstr for my case I want the data directly in the script and don't want to have to reference the excel file the data originally came from or load any packages on top of base-R. I work with sensitive data and the Excel file (and that workflow you mention) causes issues with security (if I can leave it at that).
– stackinator
Nov 21 '18 at 13:19
@jogo can you put that in the answer format? I can't quite follow what you mean. Istext="..."
shorthand for copy your console output to this space? I tried that but the row numbers the console print screws everything up. Thanks
– stackinator
Nov 21 '18 at 13:39
Use
read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
– jogo
Nov 21 '18 at 13:03
Use
read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
– jogo
Nov 21 '18 at 13:03
Why can't you use
readxl::read_excel()
? Copy/paste does not lend itself to reproducible workflows (nor does it facilitate eventual automation/scripting).– hrbrmstr
Nov 21 '18 at 13:14
Why can't you use
readxl::read_excel()
? Copy/paste does not lend itself to reproducible workflows (nor does it facilitate eventual automation/scripting).– hrbrmstr
Nov 21 '18 at 13:14
@hrbrmstr for my case I want the data directly in the script and don't want to have to reference the excel file the data originally came from or load any packages on top of base-R. I work with sensitive data and the Excel file (and that workflow you mention) causes issues with security (if I can leave it at that).
– stackinator
Nov 21 '18 at 13:19
@hrbrmstr for my case I want the data directly in the script and don't want to have to reference the excel file the data originally came from or load any packages on top of base-R. I work with sensitive data and the Excel file (and that workflow you mention) causes issues with security (if I can leave it at that).
– stackinator
Nov 21 '18 at 13:19
@jogo can you put that in the answer format? I can't quite follow what you mean. Is
text="..."
shorthand for copy your console output to this space? I tried that but the row numbers the console print screws everything up. Thanks– stackinator
Nov 21 '18 at 13:39
@jogo can you put that in the answer format? I can't quite follow what you mean. Is
text="..."
shorthand for copy your console output to this space? I tried that but the row numbers the console print screws everything up. Thanks– stackinator
Nov 21 '18 at 13:39
add a comment |
2 Answers
2
active
oldest
votes
Use read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
, e.g. for your data:
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
A 24
B 5
C 53")
or
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53")
excelss
add a comment |
I like working with the library(datapasta). It adds an addin to RStudio which enables you to paste tabular data as a data.frame definition (also other outputs possible e.g. vector). After installing the package it is available via the Addins-dropdown menu in RStudio.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412605%2fhow-do-i-reprex-reproduce-a-data-frame-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
, e.g. for your data:
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
A 24
B 5
C 53")
or
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53")
excelss
add a comment |
Use read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
, e.g. for your data:
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
A 24
B 5
C 53")
or
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53")
excelss
add a comment |
Use read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
, e.g. for your data:
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
A 24
B 5
C 53")
or
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53")
excelss
Use read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters beside text=
are set as in read.delim()
Usually I use read.table(header=TRUE, text="...")
, e.g. for your data:
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
A 24
B 5
C 53")
or
excelss <- read.table(header=TRUE, text=
" Excel.Col.1 Excel.Col.2
1 A 24
2 B 5
3 C 53")
excelss
answered Nov 21 '18 at 14:56
jogojogo
10.1k92136
10.1k92136
add a comment |
add a comment |
I like working with the library(datapasta). It adds an addin to RStudio which enables you to paste tabular data as a data.frame definition (also other outputs possible e.g. vector). After installing the package it is available via the Addins-dropdown menu in RStudio.
add a comment |
I like working with the library(datapasta). It adds an addin to RStudio which enables you to paste tabular data as a data.frame definition (also other outputs possible e.g. vector). After installing the package it is available via the Addins-dropdown menu in RStudio.
add a comment |
I like working with the library(datapasta). It adds an addin to RStudio which enables you to paste tabular data as a data.frame definition (also other outputs possible e.g. vector). After installing the package it is available via the Addins-dropdown menu in RStudio.
I like working with the library(datapasta). It adds an addin to RStudio which enables you to paste tabular data as a data.frame definition (also other outputs possible e.g. vector). After installing the package it is available via the Addins-dropdown menu in RStudio.
answered Nov 21 '18 at 13:09
ismirsehregalismirsehregal
1,7901212
1,7901212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412605%2fhow-do-i-reprex-reproduce-a-data-frame-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use
read.table(header = TRUE, sep = "t", quote = """, dec = ".", fill = TRUE, comment.char = "", text="...")
i.e. other parameters besidetext=
are set as inread.delim()
Usually I useread.table(header=TRUE, text="...")
– jogo
Nov 21 '18 at 13:03
Why can't you use
readxl::read_excel()
? Copy/paste does not lend itself to reproducible workflows (nor does it facilitate eventual automation/scripting).– hrbrmstr
Nov 21 '18 at 13:14
@hrbrmstr for my case I want the data directly in the script and don't want to have to reference the excel file the data originally came from or load any packages on top of base-R. I work with sensitive data and the Excel file (and that workflow you mention) causes issues with security (if I can leave it at that).
– stackinator
Nov 21 '18 at 13:19
@jogo can you put that in the answer format? I can't quite follow what you mean. Is
text="..."
shorthand for copy your console output to this space? I tried that but the row numbers the console print screws everything up. Thanks– stackinator
Nov 21 '18 at 13:39