I have recently changed from a PC to a mac, and have trouble trying to input my recorded audio into R.
On the PC the audio needed to be in 'My Documents' for the tuneR package to find my audio using:
readWave('audio.wav')
However I am having trouble finding the right directory that the audio needs to be on the mac for R to find it.
So far I have my audio file copied into every folder, but still no luck.
The audio can be in whatever directory you like, you just have to tell R exactly where it is. Try writing out the full path to the file, e.g. readWave('/Users/EmmaL/audiofiles/audio.wav'). To find out the path, look up the file in Finder, right click, select Get Info, and check out General -> Where:
Related
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.
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.
I am very new to R-studio. In RGui, I was used to click File / Open Script to open a new script. But in R-studio, I only see File / Open File which generaly opens any file (?). The disadvantage is that I have many files in my directory and I want to see only *.R files when opening a script - which is what Rgui does and I love it - but cannot figure out how to do the same in R-studio.
If you use windows, you can just type
~>".R"
into the search box top right (while you are in your R folder), and you will only see files that end on .R
If you click into the search box, you see your past search queries, so you won't have to type it again every time you open a script.
If you use a different OS, look for a respective search "wildcard".
edit: "show file extensions" should be activated
I had a R script open in RStudio. The file was saved many times over the course of several weeks and worked perfectly fine when RStudio was opened and closed. However, today, I restarted my computer and when I opened RStudio and more specifically the script that I mentioned, all of the R code vanished, leaving a single long row of "....." with red highlighting.
When I tried to open the R file in other text processors such as Sublime Text and Notepad++, only a line of zeroes was visible. None of my other R files were affected. I'm currently running Windows 8.1 and have the latest version of R and RStudio. What can I do to recover the code in the file and prevent something like this from happening again?
It might be an old thread and it might have been covered in 'user4458796' answer in suggestion #1 ("Use the history..."), but:
My friend had the same problem and we managed to recover the code from a 'history_database' files located on Windows at:
'C:\Users\%user%\AppData\Local\RStudio-Desktop\'
I assume there is an equivalent location in Linux in general.
Hopefully I won't get downvoted, just sharing my 2cents.
Ben.
It's not clear what happened to corrupt your file (and thus how to fix it if possible) and it is kind of ominous that you're just seeing 0's in other text editors, but I'll give you my best suggestion and some tips.
Suggestions for Attempting Recovery
Since your other R files were unaffected, you should have a messy record of your code in the history. Use the history to reconstruct your code.
Access a copy of your file from any version control, cloud, or offline backup you may have used -- git, SVN, iCloud, SugarSync, Dropbox, etc (I realize you probably wouldn't have posted this question if that were an option, but I had to throw it out there).
Use a Hex or sector editor to try to recover the data.
Use a data recover program to find an old version of your file.
Inspect your trash or recycling bin to see if it has an old version. Depending on your OS and the settings of how you (insecurely or securely) delete files, then you may be able to undelete a deleted version, even if it's not immediately available.
Try different methods of recovering text data from corrupted text files like OpenOffice's and Microsoft's suggestions.
Tips for the Future
I know that hindsight is 20/20, but a few quick tips for good measure:
Use version control. Git is supported in RStudio's GUI interface.
Have more than one version of your file. Many professors and professionals recommend writing/storing code in a text editor and using your IDE only for the working copy.
Make backups. Distinct from #2, you should backup your files to a hard drive, flash drive, or cloud service like Dropbox or Spideroak.
This is a bit of a strange question, but I thought people here might be interested.
Is it possible to have R cause a file to be opened in another program? For example, could you write a command line that would cause a music file to start playing? The potential application would be that after a model is finished running, music would start to play, alerting you to the model's completion.
In addition to system, on Windows at least you can use shell.exec which will open the file using the application specified in the Windows file associations. For example, shell.exec("file.txt") will open a text file in your favourite text editor, shell.exec("file.mp3") will launch a media player, etc.
There is audio package which allow to play wave files:
require(audio)
wave_file <- dir("C:/Windows/Media", pattern="\\.wav$", full.names=TRUE)[1] # some random windows wave file
f <- load.wave(wave_file)
play(f)
You can do this by calling the system() function.