how do I reprex reproduce a data frame in R?












0















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?










share|improve this question

























  • 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











  • @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


















0















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?










share|improve this question

























  • 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











  • @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
















0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 13:35







stackinator

















asked Nov 21 '18 at 13:00









stackinatorstackinator

1,2891519




1,2891519













  • 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











  • @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





















  • 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











  • @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



















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














2 Answers
2






active

oldest

votes


















1














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





share|improve this answer































    1














    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.






    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      1














      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





      share|improve this answer




























        1














        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





        share|improve this answer


























          1












          1








          1







          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





          share|improve this answer













          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 14:56









          jogojogo

          10.1k92136




          10.1k92136

























              1














              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.






              share|improve this answer




























                1














                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.






                share|improve this answer


























                  1












                  1








                  1







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 13:09









                  ismirsehregalismirsehregal

                  1,7901212




                  1,7901212






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      這個網誌中的熱門文章

                      Xamarin.form Move up view when keyboard appear

                      Post-Redirect-Get with Spring WebFlux and Thymeleaf

                      Anylogic : not able to use stopDelay()