Why is indentation different in editor and terminal with VSCODE? - r

After updating VSCODE to the latest version, the editor and the terminal show different indentation. Following figures present the format of the code in the editor and terminal, respectively.
Code in editor
Code in terminal
How can I keep the same indentation?

This problem is triggered by radian's auto-indent and can be solved by adding following code to the profile of radian.
options(radian.auto_indentation = FALSE)

Related

Problem with opening scripts in updated version of R

I´ve updated R on my laptop from version 4.0.3 to version 4.2.0. When I try open some of my old scripts in Rstudio, it shows an empty window. Also when I download some script I have the same problem. It is interesting, that only one script works ok, so there isn´t any problem with installation of R or Rstudio. Could somebody help me? Thanks in advance.
I think this is an encoding issue.
This worked for me (exact same problem with R 4.2.0 in Rstudio on Win11).
"Set the encoding by default to UTF-8:
Click on Tools (2nd option starting by the left on the top menu).
Choose Global Options.
An option box will appear. There choose "code" on the left menu. Under code, choose Savings and change the Default Text Encoding to UTF-8.
Now the files that were open as blank should appear with code."
See: https://github.com/ContinuumIO/anaconda-issues/issues/1609

Cannot soft wrap R source files in R studio

I'm having trouble soft wrapping .R source files in the text editor in Rstudio Version 1.4.1717. I have tried to follow advice given online but it dosn't seem to change anything on my screen. It seems it should be fairly simple using the advice here:
Disable horizontal scroll in the Source of RStudio
and here:
wrap code in R Studio text editor
I have tried various things like ticking and unticking "soft wrap R source files check box", selecting all text in the text editor before re-trying, closing and restarting Rstudio etc...but still doesn't seem to work. I'm not sure if I'm missing something really obvious?!
Update: I managed to get it working if I start a new file (File > New File > R script). Please see here:
R studio image
However, this does not seem to work for R scripts that I had already created. The bottom right of the source window, does indeed say "R Script".
Update 2
I managed to get this working if I copy pasted the entire R script to a new file ((File > New File > R script), as opposed to re-saving the current file as a newer version (using File > Save As...")
When I went to save the file, a pop-up box appeared which asked me "Choose Encoding" for which I selected the default. I wonder if the previous file had a different encoding which meant the text wrapping could not work properly? Strangely, much earlier versions of the file did NOT have any problems when when using the wrap text functionality. So it seems that something happened to one of the recent versions that is causing the issue.
Do you remember to click apply before the ok button after checking the box?
You need not restart RStudio to get the change effected.

How can I make a presentable PDF from a Jupyter Notebook?

I know that I can click on File -> Print Preview and let my browser save the result as a PDF. But that PDF will contain quite a bit of code.
Can I hide parts from the print preview or make a PDF with another tool?
Ideally, there would be magic functions:
%hide: Hide the cell and its output
%hide-code: Hide only the code of the cell, but show the output of the code
Print to PDF in the browser
In JupyterLab, you can hide the cell's input and output by clicking the side bar as demonstrated in the doc. After hiding, you can use the browser's printing menu to generate a PDF. I've tested it on FireFox and expect similar result on Chrome or Edge.
Export to PDF with nbconvert
If you aim at a native conversion from ipynb format to pdf, the nice old nbconvert tool is your friend. It usually comes together with Jupyter and can be invoked conveniently in the menu of JupyterLab File->Export Notebook As...->PDF or, in the classic Jupyter Notebook interface, File->Download as->PDF (via LaTeX).
Hiding input/output in cells can be realized by setting the cell's metadata hide_input=true and installing a nbextension as discussed in issue #155.
Print Preview menu in the classical Jupyter
Finally to your question
Can I hide parts from the print preview or make a PDF with another tool?
The "print preview" button in the classical Jupyter interface is a shortcut for calling nbconvert to generate a HTML file and redirect your browser to it. Therefore, similar configuration for nbconvert to hide input as discussed above (in issue #155) can be used. This feature is implemented by jupyter_contrib_nbextensions bundle and explained in the doc.
As the above-mentioned answers do not work for me; I found another solution:
I use an additional package notebook-as-pdf.
Read the tutorial here. It uses Chromium and is the only approach that worked for me so far reliably. The "print preview" does still not work. But it produces a clean PDF with no code input.
I do:
pip install -U notebook-as-pdf
pyppeteer-install
jupyter nbconvert --to PDFviaHTML --TemplateExporter.exclude_input=True PATH_TO_YOUR_FILE.ipynb
What did NOT work for me:
The solution above.
All the scripts mentioned in those answers

RStudio - selected code to snippet - updating r.snippets programmatically

I like using the RStudio snippets.
I thought it would be great, if i can select code and add it to the snippets by keyboard shortcut.
So i started working on it.
Even if I edit the r.snippets file programmatically, the created snippet seems only to be updated if the r.snippets file will be opened afterwards (in RStudio). As a workaround i call file.edit("~/.R/snippets/r.snippets") at the end of the code.
My question:
Does the file have to be opened or can the changes be recognised by
RStudio in another way as well?
Alternative:
It might be better practise to directly paste the selected code in the r.snippets file for the user(?)
Also asked here:
https://community.rstudio.com/t/rstudio-selected-code-to-snippet-updating-r-snippets-programmatically/20611

How to configure "Download As..."

After a day of research I managed to do a custom template for nbconvert that does what I needed to do (hide the input cells as part of a pdf conversion). However this only works in the command line. I'd like to be able to do this by chosing from the export menu, since exporting with or without output is something I'll switch frequenly.
I did some more research and found out that by adding
c.LatexExporter.template_file = 'noinput.tplx'
To my jupyter_notebook_config.py file should update the "Download As..." PDF with latex option, however it doesnt seem to do anything. Maybe there are some additional settings I should activate in the configuration file? Documentation is rather unclear in how this particular menu works.
Thanks for any help.
Check out this answer. When you use nbconvert from the command line does it use your 'noinput.tplx' template by default?

Resources