3

I have downloaded RStudio and in opening a file where my code resides it seems I have reached a capacity constraint:

The file is 2.3MB the maximum file size is 2MB
The file is too large to open at the source

Is there any way around this besides reducing the size of the file or slicing the file in two or similar?

nograpes
  • 18,623
  • 1
  • 44
  • 67
Barnaby
  • 1,472
  • 4
  • 20
  • 34
  • i guess that that file is not only code but also data: you should load data-files programmatically. – Bernd Elkemann Feb 14 '14 at 16:02
  • I use a saved Plain Text version of word, it only contains code, although word seems to contain other meta data avobe and below unsure if the plain text also does. – Barnaby Feb 14 '14 at 16:04
  • 1
    The whole source code of the data.table package is about 1.6 MB. I don't believe that you have written 2.3 MB of usable code. – Roland Feb 14 '14 at 16:09
  • R studio will prefer raw text file, possibly with extension of `.R`. Open a new file in Rstudio and copy/paste the code from word. – Roman Luštrik Feb 14 '14 at 16:12
  • I guess I have to past it in the console. The code is 700 pages of code in plain text word, possibly the code can be made shorter by using the apply family or other loop functions as it includes some repetitions of the same training functions for new data. – Barnaby Feb 14 '14 at 16:22
  • Seems to take a long time to past it, waiting – Barnaby Feb 14 '14 at 16:45
  • Instead of pasting, you could try `source("your_file.R")`, maybe with `echo=TRUE` if you want to follow the execution. 2.3MB is a _lot_ of code though. I would consider simplifying it, especially if you'll need to revisit it in the future. – Peyton Feb 14 '14 at 16:57
  • 1
    @Barnaby 700 pages..wow. Sounds like you're probably writing a couple of package worth of code. I would try to convert it to vactorized and apply friendly format. I would also split the code by functionality in multiple source files and use **source** command to read the code from the file. Good luck – Dev Patel Feb 14 '14 at 16:58
  • 2
    There's no way I would trust Word to not muck up something in that 700 pages of code. You should review every single line. And re-run the test suite. What do you mean, there's no test suite? – Spacedman Feb 14 '14 at 17:00
  • If you have 700 pages of code, then you most definitely need to take a class in how to write code in general. There is no way you should even consider having a given function (or code module, or subroutine) longer than a few pages. Further, you will most certainly find your code fails, and have zero chance of debugging that monstrosity. Learn to start small and prove out each piece by itself. – Carl Witthoft Feb 14 '14 at 18:00
  • Carl I totally agree, the longest function, code module or subrutine I have is a few pages long. However there are over 100 different functions in the model and the code works in a version where the selection of variables and models is done semi-manually. The issue is that the code grew as I added a rutine for selection of variables and models. I think there are two aspects to it one is that I have to learn how to loop the 100 functions for different combinations of variables and the second is that I have to make the model selection a less cumbersome rutine. – Barnaby Feb 14 '14 at 18:41

2 Answers2

1

The answer is very likely no, you cannot do this. I refer you to this question on the RStudio support forum, where they suggest that the editor is not capable of handling such files:

Is your file much larger than 5MB? The limit is there for your protection--for both the editor component which is not infinitely scaleable, and also when resuming your session you may appear to hang.

I fully agree with the comments: it is doubtful that properly written code could reach this size. I suspect that what you have done is simply copied hundreds of lines of codes hundreds of times rather than iterating through it.

If you really need to do this, you can use Notepad++, NpptoR, and plain R which is a reasonable combination to work with enormous code files.

NCC1701
  • 139
  • 11
nograpes
  • 18,623
  • 1
  • 44
  • 67
1

If the above error comes when trying to load a large script file. There is a work around for this.

  1. Create a temporary script file say, temp_script.r, with small content. Does not matter what content it is, maybe couple of lines from the original script files.

  2. Open temp_script.r in R Studio

  3. In another text editor say Notepad, open the same file i.e temp_script.r

  4. Copy and Paste the original large script file into temp_script.r in Notepad.

  5. Save temp_script.r in Notepad.

  6. The opened temp_script.r in RStudio with be auto refreshed and now you will see the large codes have been loaded into RStudio's editor.

Good Luck.

Saravanan K
  • 672
  • 3
  • 10
  • 27