How do I upload a local csv for use in Google Colab with an R kernel? - r

The only results for this question that I see is to use Python to either mount the drive or load through git/gist, etc.
This is how I'm currently loading the R kernel (How to use R with Google Colaboratory?): load the Demo.ipynb and it somehow retains the R kernel for me when I save a copy.

I'm dumb and figured out a workaround
In case anyone else has this problem:
1
Click on the arrow to expand the window, Files -> Upload
It should give you a warning that the files will get deleted after the runtime is refreshed.

Related

R Studio will not open .r files in source

I have used R for years and, until recently, have had few problems. However, since the last update, R keeps erasing scripts that I have saved in the Source window; then, when I go to retrieve them from recent files, it opens a script that has a title but zero code. I am able to open the files in notepad and copy/paste them back in, but I would like to know how to resolve this issue so that I could use R in the same expeditious manner as previous.
To reiterate with slightly different wording: R opens my saved scripts (.r files) as codeless source windows; there is simply a number 1 there and nothing else, though the title is displayed. I did save one as a text file and tried to open it that way but got the same results. Opening files in Notepad and copying/pasting them does work, but obviously R should be able to open R scripts and display R code.
Can anyone shed some light on this issue?
Thank you,
Matt
It's not sophisticated, but I would
uninstall R & RStudio
reset/remove the "internal state" stored by RStudio
reset/remove the "preferences" stored by RStudio
reinstall R & RStudio
Here's good documentation from RStudio for points 2 & 3, depending on your version and OS: https://support.posit.co/hc/en-us/articles/200534577-Resetting-RStudio-Desktop-s-State

how to open the .ipynb file in readable format

I have got downloaded a file that got downloaded in a format .ipynb extension but its not in a readable format. Can anyone help me to figure out how to make it in a readable format? Attaching a screenshot of the file when I tried opening it in notepad.
how to open it in readable format
One of the easiest ways to just view a notebook file that is also 100% secure in case what you are being sent is sensitive: nbpreview.
When you go there it asks you to choose a local file. The file isn't uploaded anywhere. It remains in your browser's local cache so it is useful for sensitive stuff that cannot be public.
Similarly, you can upload it to the notebook{sharing}space which is billed as "the fastest way to share your notebooks". It would provide you with a link to view the notebook you have and can be private if you limit sharing the link.
If the notebook can be posted to Github (repository or gist) or online, you can point nbviewer at it and have it rendered nicely. In fact, although it is technically 'static', nbviewer can render some interactive Plotly plots and widget controls that enable playing back animations comprised of frames. This rendering form is also very nice for sharing with non-programmers as the GitHub cruft is not surrounding the content.
You can use Jupyter running in your browser and backed by a free Jupyter community-run service to view the notebook file as an active notebook, on what is equivalent to a temporary remote machine.
Go to Try Jupyter and select either 'JupyterLab' or 'Jupyter Notebook' from the offerings presented. I'd suggest JupyterLab as the steps outline below are made easier as you have the file navigation pane on the left.
After your session spins up in your browser, if you chose JupyterLab, drag your file from your local machine into the file navigation pane on the left side. It will get a gray dashed line around it when you have dragged it to the right place. Drop it in and let it upload. Now double click on it to open it.
If you don't want to drag-and-drop or you chose Jupyter notebooks (classic notebook interface) make a text file and paste in the content you showed. (It's json format as that is the underlying .ipynb format presently.) Save that file with an .ipynb extension. You should then be able to open it the Jupyter Dashboard. (Note the following in the rest of this section was written before the 'Try Jupyter' offerings were switched to using the exerpimental JupyterLite and so your mileage may vary. If you drag-and-drop into JupyterLite, it actually is in your machine; however, it is in a virtual system in your browser that your local file system cannot access directly. To get what this section was specifically written for now, go here and click on the launch binder badge to trigger a session on a true remote machine served by MyBinder.) You used to click on the logo in the upper left to get to the dashboard but it will now take you to JupyterLab and you can double click to open your notebook file. If you really need the classic dashboard, change the end of the URL to change /lab to /tree.
Note because the environment backing your notebook hasn't been set up to handle everything, you'll be out of luck for now trying to run it. You'd have to add your pokemon.csv and install anything else besides pandas. There are ways to use the MyBinder system to handle that as well; however, probably best learned about later this stage.
The MyBinder session is temporary and unique to you. It will close after 10 minutes of inactivity and no longer be accessible. You can always open another session later and redo the steps. Or learn about other options eventually.
Related:
Nbpreview and a lot of the related tools mentioned here are also covered in Sharing R code in Jupyter notebooks.
(These following suggestions mostly assume the notebook is already online, usually at Github. You can still use a local notebook by uploading it to the session as I suggest above. They do though provide additional ways to learn about using MyBinder to serve active notebooks in your browser.)
How to save code file on GitHub and run on Jupyter notebook?
Run a Jupyter notebook directly online (without downloading it locally)
You need Jupyter Notebook in your machine. That is one option. Otherwise, you can upload the file into GitHub and open the .ipynb file from there.

Unable to load workspace in basic R Gui

a complete newbie to R here. Learning through trial and error. Most bugging issue is saving and loading workspace in the basic R Gui, I haven't started working with R Studio yet. I'm learning as I go. When saving a workspace - which through research I'm told saves all the objects therein - when using the traditional way of File>Save workspace> directory.RData it saves all right to the computer file directory. I also use the command save.image('.RData') when it comes to saving the workspace. The issue is when it comes to loading a previous R session. When I use File>load workspace or even load('<directory.Rdata'>) all I get is a blank screen with this message:
[Previously saved workspace restored]
No data appears below the above message in R. I only manage to retrieve my work if I save it as a text file through Save to file>(directory).txt. Thereafter I open notepad and copy paste to R. This means all graphs drawn in tthe previous session get lost despite this being a tedious job all the time.
I would appreciate if someone advised me step by step on how to save and load work in R. I have tried all online suggestions including from this forum.
use of code to load not working despite multiple enter tries(>)
Ps: when closing basic R Gui, I always click yes to the prompt "Save workspace image" even after saving with the code save.image() or File>save workspace techniques. But still, I can't retrieve my workspace either way. Even when I click 'no' to the prompt, I'm still unable to load workspace in a future R session.

Saving an R-Script results in empty file

I have recently started using R for uni. I want to save my code using either save as or ctrl+s. However, the saved file is empty more often than not. For some reason, the files save normally on a few occasions. However, they also became empty after saving changes to the script.
I couldn't find any solution for the problem, neither here nor anywhere else.
I am using RStudio installed via Anaconda on an Windows 10 x64 Notebook, if that helps.
Thanks a lot for the responses! I'd be glad to provide more details if needed!
This is what the saved files look like from File Explorer:
I just meet the exactly same problem. I solved it by checking and changing RStudio -> File -> "Save as Encoding" from "ISO-8859-1 (System default)" to "UTF-8", then the file was saved. I'm trying to recover my previous 0kb files...
i couldn't reproduce the error but i also don't like to use the anaconda environment.
if the problem is saving the text file than may i suggest to do just that and save the code in a regular .txt file?
if this is not an option you can try to find out what happens if you save the r studio code on a different drive (or usb/flash drive)
###########################################################
EDIT 14.07.2022
Interestingly enough, just today (14.07.2022) I had the same problem. After installing R 4.2.1 everything worked fine until I changed the encoding (from utf-8 to windows 1252), at which point all the files in my project were overwritten and are now empty. Changing back to an older version of R (4.1.3) allowed me to display/save/use all scripts again (from backups).
Using the answer provided by #Shidan it is possible to open the data in R-4.2.1 as well.
This problem does not seem to be connected to Anaconda but an encoding issue between Rstudio and any R distribution above (and including) 4.2.

RStudio error message - the device does not recognize the command

I am repeatedly getting the error message:
Error Save File: ' The device does not recognize the command' popping up over and over (every 15 seconds) - even when I don't click save or when I do click save.
I also can't load a R file that is in my folder - I have to open it up in notepad and copy it paste it to even see it.
Can someone let me know how to fix this? I have the latest version of Rstudio installed.
This happens when the drive memory runs out of space. As a quick fix measure, try copying all the code to an another R script file/ notepad and you might save it luckily. Long term solution would be to clear the cache and upgrade your hard drive..
This can also happen if you are reading from a file that is open in another program in some cases. Generally speaking R has no issues reading in files that are open / read only (i.e. import a CSV file) if that file is in use by another process. However, there are some cases where the read-only restriction from a locked file being imported causes the
Error Save File: ' The device does not recognize the command'
message to persist even if you are not trying to to read from or write to the locked file.
As a specific example, if you are using openxlsx to import an xlsx file that you are also viewing in excel, after reading the xlsx file in, you will get the error whenever you make changes to your R script and stop for more than a few seconds, or when you try to save the R script, even though it is not touching the xlsx file. However, if you close R Studio and re-open your script, you will notice that the issue will not appear until you try to read the xlsx file in again.
Met error "The device does not recognise the command" today. Not due to disc space but due to an r script that was somehow no good, even though file extension OK. After a very frustrating time when I couldn't copy to a fresh R script or shut down the project, saved content of troublesome r script to another older r script, deleted it and all OK - e.g. could now open up another new script that saved with no problems.

Resources