Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source pane displays non-empty R script as empty #1623

Closed
maciejkasinski opened this issue Oct 18, 2017 · 40 comments · Fixed by #1901
Closed

Source pane displays non-empty R script as empty #1623

maciejkasinski opened this issue Oct 18, 2017 · 40 comments · Fixed by #1901

Comments

@maciejkasinski
Copy link

@maciejkasinski maciejkasinski commented Oct 18, 2017

After opening an existing project in RStudio, one of my scripts "how_to_use-Ex.R" is displayed in source pane as though it was empty. You can see it isn't (size of 1.8 KB).
image
Fortunately, the script has not been erased. Reopening the script in RStudio solves empty display problem.

OS X 10.11.6 (15G31)
RStudio 1.1.383

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Oct 18, 2017

Does this always occur when you restart the IDE with that file open, or was this a one-time issue you noticed?

@etienne-s
Copy link

@etienne-s etienne-s commented Oct 19, 2017

It happened to me as well today. Closing the project and restarting RStudio did not solve anything, but reopening the script did.

@kevinushey For me it was a one-time issue.

Windows 7 x64
RStudio 1.1.383

@maciejkasinski
Copy link
Author

@maciejkasinski maciejkasinski commented Oct 19, 2017

It happened two or three times. Maximum of 3 scripts were empty at once.

@tinu-schneider
Copy link

@tinu-schneider tinu-schneider commented Oct 21, 2017

Same here.
If I open the (emptied) script in a new window ("Show in new window"), close this new window and open the file again from the files menu, the content shows up as expected.

@kevinushey It happens from time to time, up to now in Shiny projects only.

@jmcphers A repro is hard to build - it happens randomly (up to now I dont see any pattern)

Session info ---------------------------------------------------------                  
 version  R version 3.4.2 (2017-09-28)
 system   x86_64, mingw32             
 ui       RStudio (1.1.383)           
 language (EN)                        
 collate  German_Switzerland.1252     
 tz       Europe/Berlin               
 date     2017-10-21    

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Oct 23, 2017

Can you share the output of a diagnostics report? If the document is long, you might want to upload it as e.g. a GitHub gist and share a link to that.

@tinu-schneider
Copy link

@tinu-schneider tinu-schneider commented Nov 5, 2017

The issue did not happen again - so I can't upload any diagnostics report.

@etienne-s
Copy link

@etienne-s etienne-s commented Dec 4, 2017

It happened to me again today. Here is a diagnostics report: diagnostics-report.txt

Note that I removed old log lines and that I anonymized a few elements. I kept the latest log lines but they were generated before I opened that project.

Also note that this morning I updated R from 3.4.2 to 3.4.3 (from Rgui, using installr::updateR()), just saying this in case it would be related.

@jmcphers
Copy link
Member

@jmcphers jmcphers commented Dec 4, 2017

@kevinushey I pulled some state from someone experiencing this issue (ping me offline if you'd like the full data). What's happening in at least some cases is that the source database migration from 1.0 to 1.1 is failing for some files; the file gets moved, but its contents aren't transferred. In example I have, there isn't an obvious culprit -- some files are migrated successfully, but others (most) are not.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jan 2, 2018

I was able to reproduce this issue in the following way.

  1. Create an RStudio project,
  2. Open that project with RStudio v1.0,
  3. Open a few files in that project,
  4. Shut down the IDE,
  5. Open the project with RStudio v1.1,
  6. Try editing one of the open files,
  7. Close and re-open RStudio v1.1,
  8. Notice that the open document is empty.

I think this is because we don't fully migrate to the new format on the first transfer of files. On the first open of RStudio v1.1, the sources folder looks like this:

$ tree
.
├── per
│   ├── t
│   └── u
├── prop
│   ├── 2646FB5C
│   ├── 28A9DEA3
│   ├── DC6A99FB
│   └── INDEX
└── s-F955001D
    ├── 244D0217
    ├── 88798333
    ├── FAE2342D
    └── lock_file

After a close + re-opening of the IDE, it looks like this:

$ tree
.
├── per
│   ├── t
│   └── u
├── prop
│   ├── 2646FB5C
│   ├── 28A9DEA3
│   ├── DC6A99FB
│   └── INDEX
└── s-1794F329
    ├── 244D0217
    ├── 244D0217-contents
    ├── 88798333
    ├── 88798333-contents
    ├── FAE2342D
    ├── FAE2342D-contents
    └── lock_file

Because those -contents files aren't populated on the first run, we end up with property files written out with no contents after an autosave. To mitigate this, we should extract the contents out of each properties file during migration and write the associated -contents file.

@jmcphers
Copy link
Member

@jmcphers jmcphers commented Jan 3, 2018

Backported fix to 1.1 in 160fe9d.

@ronblum
Copy link
Contributor

@ronblum ronblum commented Jan 8, 2018

We have a preview release for an upcoming 1.1 patch at
https://www.rstudio.com/products/rstudio/download/preview/
It addresses this bug. If any of you are still seeing this issue, you can try out the preview and see if it resolves the problem for you.

@gimeno09
Copy link

@gimeno09 gimeno09 commented Dec 5, 2019

Hi I still have this issue in my system- windows 10 and RStudio version Version 1.1.456 – © 2009-2018 RStudio, Inc.. I am seeing all data when i open the file with notepad but while opening in R, its blank file.

have we nailed down the issue and is the solution available?

@johnDowee
Copy link

@johnDowee johnDowee commented Jan 11, 2020

Hi, the issue still persists. I did numerous re-installation but no way out. I am doing it with Anaconda3-2019.10-Windows and RStudio 1.1.456. The notepad shows the script intact but Studio editor is blank and knit produces output document correctly. It's funny and irritating...

Please share if there is a solution.

@johnDowee
Copy link

@johnDowee johnDowee commented Jan 11, 2020

Hi, the issue still persists. I did numerous re-installation but no way out. I am doing it with Anaconda3-2019.10-Windows and RStudio 1.1.456. The notepad shows the script intact but Studio editor is blank and knit produces output document correctly. It's funny and irritating...

Please share if there is a solution.

I partially bypassed the issue by installing a higher version of RStudio outside Anaconda after reading this Update RStudio in Anaconda. Almost sure the issue is with RStudio 1.1.456.

@mmahmoudian
Copy link

@mmahmoudian mmahmoudian commented Mar 17, 2020

I am facing this issue on version 1.2.5033 of Rstudio server on hosted on my Ubuntu 16.04 desktop. The symptoms (file tree) are very similar to what @kevinushey mentioned. I usually open the code in detached mode (detached from the panes by clicking "show in new window") to work on it on another vertical monitor. This probably the reason that every time I open the Rstudio I get another window open having two tabs, both are the same exact file and of course empty and not saved! every time I press the x on the top right corner of the tabs and select "Don't save", the next time I open the Rstudio it re-appears again!

image

@Stalwart-GS
Copy link

@Stalwart-GS Stalwart-GS commented Apr 1, 2020

I came across this issue while I was facing the same problem, but after various hit and trials and understanding what can be the causes of this problem,
In my humble opinion, I think this problem is arising with the R Studio that come along with anaconda distributor because after various updations and looking up on the internet.
This showing of empty files even I just updated it a second ago, is now solved when I installed the R studios from the origin site of R Studios with the latest version installed.
and then uninstalled that the version I got with anaconda distribution.
Personally, my issue is solved, So you can give this method a try in case if you have not already.

@Stalwart-GS
Copy link

@Stalwart-GS Stalwart-GS commented Apr 1, 2020

Hi, the issue still persists. I did numerous re-installation but no way out. I am doing it with Anaconda3-2019.10-Windows and RStudio 1.1.456. The notepad shows the script intact but Studio editor is blank and knit produces output document correctly. It's funny and irritating...

Please share if there is a solution.

You can try what I just tried and it solved the issue for me.

@mmahmoudian
Copy link

@mmahmoudian mmahmoudian commented Apr 1, 2020

I think this problem is arising with the R Studio that come along with anaconda distributor

@Stalwart-GS I personally hate anaconda and what it does to my system. it's been years that I'm avoiding it, and I've always (since day 1) have installed Rstudio from their official .deb file, and yet I have this issue, hence your hypothesis, unfortunately, is wrong (or at least not completely correct).

@robbwh
Copy link

@robbwh robbwh commented Apr 2, 2020

@mmahmoudian There could be an issue with your workspace. I fixed my friend's Rstudio with this issue by pressing control-shift-F10 to clear the workspace, closing out of Rstudio, and opening it back up.

@mmahmoudian
Copy link

@mmahmoudian mmahmoudian commented Apr 3, 2020

@robbwh just checked it, nope, it does not fix the issue. This is clearly a bug in the way Rstudio is storing the open files

@ronblum
Copy link
Contributor

@ronblum ronblum commented Apr 3, 2020

@mmahmoudian What version of R are you using and what browser are you using to connect to RStudio Server? And does the issue only occur when you have a file in a separate window?

@villalbac
Copy link

@villalbac villalbac commented Apr 5, 2020

I am facing this issue on version 1.2.5033 of Rstudio server on hosted on my Ubuntu 16.04 desktop. The symptoms (file tree) are very similar to what @kevinushey mentioned. I usually open the code in detached mode (detached from the panes by clicking "show in new window") to work on it on another vertical monitor. This probably the reason that every time I open the Rstudio I get another window open having two tabs, both are the same exact file and of course empty and not saved! every time I press the x on the top right corner of the tabs and select "Don't save", the next time I open the Rstudio it re-appears again!

image

I had the issue with the Anaconda and RStudio 1.1.4.56. I opened the file in a new window or new project and now is working fine. No re-installation and no complicated fixes. It might be something on the configuration and the rendering. Forgot to mention that I'm on Windows 10 in case it has anything to do. Thank you!

@hansobro000
Copy link

@hansobro000 hansobro000 commented Mar 7, 2021

This happened to me as well. As mentioned earlier, my issue had to do with the Anaconda version. I fixed it by installing Rstudio and then re-downloading the latest version from their official website.

@samzipper
Copy link

@samzipper samzipper commented May 4, 2022

Had this issue after updating to R 4.2.0/RStudio 2022.02.2 Build 485 and @Azures729 solution worked as well.

@Futats
Copy link

@Futats Futats commented May 12, 2022

Same as @samzipper : I just uninstalled RStudio and installed from RStudio.com and I still encounter this issue in build 485. Reopen in UTF-8 does make things visible, but all .r files I have tried open apparently blank when opened with my system default ISO-8859-1.

Release: RStudio 2022.02.2+485 "Prairie Trillium" Release (8acbd38, 2022-04-19)

@ronblum
Copy link
Contributor

@ronblum ronblum commented May 12, 2022

@samzipper and @Futats what operating systems are you using?

Triage: Possible regression.

@ronblum ronblum added the triage label May 12, 2022
@ronblum ronblum reopened this May 12, 2022
@samzipper
Copy link

@samzipper samzipper commented May 12, 2022

@ronblum Thanks for investigating - to provide some more detail, re-opening with encoding works, but I have to re-do it with each source file. Setting UTF-8 as default it doesn't seem to carry over from file to file, either within the same RStudio session or across multiple sessions.

RStudio: "Prairie Trillium" Release (8acbd38, 2022-04-19) for Windows
R: R version 4.2.0 (2022-04-22 ucrt) -- "Vigorous Calisthenics"

Windows:
Edition Windows 10 Pro
Version 21H2
Installed on ‎8/‎4/‎2021
OS build 19044.1586
Experience Windows Feature Experience Pack 120.2212.4170.0

@Futats
Copy link

@Futats Futats commented May 12, 2022

For me, setting UTF-8 as the default worked for all .r files I tried and persisted across RStudio reboots, but the issue comes back for every file if I return to my system default ISO-8859-1.

RStudio: "Prairie Trillium" Release (8acbd38, 2022-04-19) for Windows
R: R version 4.2.0 (2022-04-22 ucrt) -- "Vigorous Calisthenics"

Windows:
Windows 10 Enterprise
Version 1809
OS build 17763.2746

@AlexSiormpas
Copy link

@AlexSiormpas AlexSiormpas commented May 13, 2022

I was able to fix by going to

File > Reopen with Encoding... > Select UTF-8

I also chose Set as default encoding for source files

God bless you! The solution worked for me too!

@jgutman
Copy link
Contributor

@jgutman jgutman commented May 13, 2022

FYI @kevinushey penny for your thoughts

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented May 13, 2022

This appears pretty serious to me. It's likely related to the changes in R 4.2.0 on Windows to use UTF-8 as the default locale.

I can also reproduce whenever I try to re-save a "large" document (larger than 1kb on disk) with a non-UTF-8 encoding (via File -> Save with Encoding). When I do this, the file saved on disk is now size 0. As far as I can see, there is no error logged or anything else; we're just silently losing the file contents.

My guess is that the code here is silently failing for some reason:

std::string encoded;
error = r::util::iconvstr(contents,
"UTF-8",
pDoc->encoding(),
false,
&encoded);
if (error)
{
error = r::util::iconvstr(contents,
"UTF-8",
pDoc->encoding(),
true,
&encoded);
if (error)
return error;
module_context::consoleWriteError(
"Not all of the characters in " + path +
" could be encoded using " + pDoc->encoding() +
". To save using a different encoding, choose \"File | "
"Save with Encoding...\" from the main menu.\n");
}

If that's the case, stepping through this code may be fruitful:

rstudio/src/cpp/r/RUtil.cpp

Lines 145 to 200 in 925ba91

core::Error iconvstrImpl(const std::string& value,
const std::string& from,
const std::string& to,
bool allowSubstitution,
std::string* pResult)
{
std::vector<char> output;
output.reserve(value.length());
void* handle = ::Riconv_open(to.c_str(), from.c_str());
if (handle == (void*)(-1))
return systemError(R_ERRNO, ERROR_LOCATION);
const char* pIn = value.data();
size_t inBytes = value.size();
char buffer[256];
while (inBytes > 0)
{
const char* pInOrig = pIn;
char* pOut = buffer;
size_t outBytes = sizeof(buffer);
size_t result = ::Riconv(handle, &pIn, &inBytes, &pOut, &outBytes);
if (buffer != pOut)
output.insert(output.end(), buffer, pOut);
if (result == (size_t)(-1))
{
if ((R_ERRNO == EILSEQ || R_ERRNO == EINVAL) && allowSubstitution)
{
output.push_back('?');
pIn++;
inBytes--;
}
else if (R_ERRNO == E2BIG && pInOrig != pIn)
{
continue;
}
else
{
::Riconv_close(handle);
Error error = systemError(R_ERRNO, ERROR_LOCATION);
error.addProperty("str", value);
error.addProperty("len", gsl::narrow_cast<int>(value.length()));
error.addProperty("from", from);
error.addProperty("to", to);
return error;
}
}
}
::Riconv_close(handle);
*pResult = std::string(output.begin(), output.end());
return Success();
}

@kevinushey kevinushey assigned kevinushey and unassigned jgutman May 13, 2022
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented May 13, 2022

I've filed #11206 to track this particular iteration of the issue. Note that the issue should only effect RStudio on Windows with R 4.2.0. Please direct any other follow-up there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.