I am using Github's atom text editor.
Most of the times, when I modify a single line in a file, git diff shows a lot of lines as deleted and added back in this way
- #op_contact = "Not Available"
+ #op_contact = "Not Available"
This causes inconvenience in code-reviews and hence I am forced to use other editors like SublimeText.
It looks like some simple setting should fix this, but I am not sure how to do it and I don't know what to search for. There are some related questions, like this one but I want to fix it from Atom editor, as this problem is not present in SublimeText.
Atom version: 1.3.1
You are probably searching for the Whitespace package which ships with Atom by default.
It removes unnecessary whitespace at the end of each line. Disable it and your suspicious line changes should be gone.
Related
I was getting this error when running devtools::document but had no idea how to troubleshoot. The file that popped up on my installed package when I entered ?MyPackage-package did not match the text in MyPackage-package.R at all. I initially suspected it might have been from adding the awesome citation functionality from RDpack, but this was not the culprit. How did I go about ultimately fixing the problem?
The error resulted from incorrect formatting in my PackageName-package.R file.
I had heavily edited the file created by usethis::use_package_doc(), and added all of my roxygen comments Below the default content added by usethis. After looking at the documentation for merTools, I saw that it was ok to have the stuff I understand to be important for roxygen2 to make the .Rd files after and not before all the other roxygen comments.
After moving the stuff created by usethis::use_package_doc() (and not just the NULL line; that was already at the end) to the bottom of the .R file, everything seemed to render fine and this error disappeared.
I successfully set up R in my new Atom editor and can get in-line results using the Hydrogen package. I just noticed, however, that when I run lines to obtain "R Documentation" that would pop up automatically in RStudio, Hydrogen only gives me a check mark in-line result with no associated documentation.
Here is what is going on in my Atom editor when I run ?plot
Here is what happens in RStudio (bottom right pane), which I am hoping I can get in Atom
How can I get this working in Atom?
try hydrogen -> Toggle inspector
I had the same question and actually made a little progress. Perhaps someone more experienced than I can use this to make a package to enable an in-atom help documentation panel for us :)
Anyway you can install the atom package 'script' which will properly output some, but not all, help documents. I have an example of one working & one not working.
Working ?read.csv
Not-working ?geom_bar
Sublime text has a feature that allows you to highlight multiple identical selections to rename variables quickly. It is initiated with Ctrl+D on your keyboard. Most importantly it is context aware. If I want to rename the variable is to xy, it won't, for instance, rename this to thxy.
How do I get Atom to recognize scope? If I Ctrl+D the same as in Sublime it does not differentiate between is and this.
Highlight the first two letters in this code chunk below (ie 'is') and press Ctrl+D. It's jumps to the 'is' in this.
is
this is really cool
code
this is really cool
code
My answer is valid for JavaScript, for which I had the same question as you did.
I installed two more packages in atom:
https://atom.io/packages/refactor
https://atom.io/packages/js-refactor
The first one is the core package i think and the second one is javascript-specific. It worked after installing and restarting atom one time.
For you this package alone should do: https://atom.io/packages/cpp-refactor
I need to convert the line endings of some mock data into Unix format. I'm using Atom editor on Win 7.
Looking online, I found an Atom package to convert line endings, but the package said it is deprecated since Atom now has this as a standard feature.
I cannot find any such standard feature in Atom - and Atom's documentation doesn't even know what line-ending conversion is.
'About Atom' tells me Atom is up-to-date with v.1.23.3
This, to me, seems a paradox.
(And no, I cannot just use Notepad++.)
I've looked around at a lot of solutions, but have not found one that will actually work.
The built in line-ending-selector package supports this use case: https://atom.io/packages/line-ending-selector
The package's documentation describes how to do this:
You can click the line ending in the status-bar to open a modal with the line ending options. Selecting a different line ending will change each line of the file in the active editor.
If you prefer to use the keyboard, you can also open the command palette (cmd-shift-p on macOS), type Convert and then use the Line Ending Selector: Convert to LF and Line Ending Selector: Convert to CRLF commands from there.
Go to Preferences under Atom menu. Uner the settings window, go to Packages. In packages search on line-ending-selector. This reveals a core package that is loaded with Atom. Scroll down the line-ending-selector page and you see the header Settings. Below that you can choose the default line endings. You can choose LF, CNTL-LF, or OS. Set this to the value you want.
In R I always like to print out the script since it gives a good overview and one can adjust eventual errors. I like the syntax highlighting in R-Studio because it facilitates reading and fast comprehension of code.
Is there a way to print out the text with the highlighting I see in the editor?
Its not an R-Studio solution, but notepad++ will print R source with syntax highlighting.
RStudio will not print in colour, but it's easy to save the code as a PDF; in this case the syntax format is preserved. My favourite package is knitr.
library(knitr)
stitch("file_name.R")
The default output is PDF/Markup in .tex. If you prefer not to typeset, running the below will export as .html
stitch(script="file_name.R", system.file("misc", "knitr-template.Rhtml", package="knitr"))
Brief explanation
The reason this is an answer to this question in because of the last line of the question:
Is there a way to print out the text with the highlighting I see in
the editor?
so we are not limited to only and only using Rstudio software here.
After exploring the awesome answer by #rrg and realizing that it runs the code line by line, I wrote a comment below his answer and continued googling. My problem is that the code I wrote is so large and so time consuming to run that running it for the sake of having a syntax highlighted version is not feasible.
Most of the solution out there online involves having notepad++ which is a Windows application and I'm a dedicated Linux user, so I searched for a way I can do this in Linux (and possibly Mac)
The way I solved it:
Inspired by a blog post, I used the famous and beloved Vim to convert R to syntax highlighted HTML and then because you can open HTML in your browser, you can what ever you want with it (print, screenshot, etc.)
Activate synax highlighting in Vim:
open terminal
then open the vim config file by typing vim ~/.vimrc
press i from keyboard to go to "insert mode"
go to the end of the file using arrow keys on your keyboard
type syntax on at the end of the file
now you need to save and exit. For this you need to press Esc button from keyboard to come out of "insert mode" and then type :x and press Enter to save and close the file.
if you want to change the color scheme of the syntax highlighting, visit the bottom part of this website
From terminal open your file with Vim:
vim YOUR_FILE_PATH
Having you R code open in vim, you can turn on the line numbers if you like by pressing Esc and then write :set number and press Enter.
For converting R to HTML, press Esc to make sure you are not in "insert mode" and then type :TOhtml and press Enter. This will result is having a split window in terminal, half is your R code and the other half id your new HTML code.
For saving the files, type :x along with Enter button from keyboard twice to save both files (your R file will be unchanged if you have not typed anything extra in it and your HTML file will be created with the same name near your R code)
Now open it with your favorite browser (in my case Vivaldi) and do what ever you want (in my case converting the whole HTML into PNG)
Best way:
download https://github.com/jaredpetersen/codeprinter and paste in the r code. then choose syntax highlighting Xcode
For those using a Mac (and thus without access to Notepad++) cutting and pasting into Xcode and printing from there will also work.
As with Ron Jensen's earlier comment, this isn't an R Studio solution, but in the interests of "just getting it to work", I hope this helps someone.