In R (just default mac R) on my mac machine, when I see the help page with
> ?read.csv
it appears on a new window with a beautiful format.
Now I'm using the Sublime text 3 for R (with SublimeREPL:R, R-Box, R-Extended etc.) on the mac machine, many things work fine.
My question is:
when I type the help page (?read.csv), the contents appear on the same ST3 window with a plain format.
Is there any way to make it appear on a new window such as a HTML page (in Safari)?
Set the help_type option to "html":
options(help_type = 'html')
and it will open help files in the default browser. If you put that in your .Rprofile, you won't need to set it for each session.
Related
I have downloaded an image (in fact several images using a for loop) using the below code. However, these images are not opening up, though they seem to have got downloaded completely. In fact these images are not opening up in plain Photo editor or Paint etc., tools. Appreciate inputs and what shall be done..
Below is the code that I tried with for loop:
p <- c("http://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png",
"http://assets.pokemon.com/assets/cms2/img/pokedex/full/002.png",
"http://assets.pokemon.com/assets/cms2/img/pokedex/full/003.png",
"http://assets.pokemon.com/assets/cms2/img/pokedex/full/003_f2.png",
"http://assets.pokemon.com/assets/cms2/img/pokedex/full/004.png")
p
for (url in p)
download.file(url, destfile=file.path("C:/Users/xyz/Desktop/test",basename(url)))
library(imager)
# loading only first image for viewing
i <- load.image("C:/Users/xyz/Desktop/test/001.png")
plot(i)
Then I just downloaded a single file giving a simple destination name and tried to load and display using the below code.
download.file("http://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png",
destfile=file.path("C:/Users/xyz/Desktop/test","first_img.png"))
i_s <- load.image("C:/Users/xyz/Desktop/test/first_img.png")
plot(i_s)
In both the cases I am getting the below error message.
Error in read.bitmap(file) :
File f: C:/Users/xyz/Desktop/test/001.png does not appear to be a PNG, BMP, JPEG, or TIFF
Same way, if I try to open the downloaded images using Photos, Photos editor, Adobe, Paint etc., I get similar messages like format not supported, unable to load photo, etc., messages. However, note that if I simply copy and paste the image url in the browser, the image appears perfectly in the web page.
Appreciate inputs on what can be done here.
Loos like you have to set mode = "wb" in download.file. The manual says:
The choice of binary transfer (‘mode = "wb"’ or ‘"ab"’) is important on Windows, since unlike Unix-alikes it does distinguish between text and binary files and for text transfers changes ‘\n’ line endings to ‘\r\n’ (aka ‘CRLF’).
On Windows, if ‘mode’ is not supplied (‘missing()’) and ‘url’ ends in one of ‘.gz’, ‘.bz2’, ‘.xz’, ‘.tgz’, ‘.zip’, ‘.jar’, ‘.rda’, ‘.rds’ or ‘.RData’, ‘mode = "wb"’ is set so that a binary transfer is done to help unwary users.
So for the single file try:
download.file("http://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png",
destfile=file.path("C:/Users/vsvas/Desktop/test","first_img.png"),
mode = "wb")
Is there a simple way to copy the selected output in RStudio's console as plain text?
For example, I have this output:
And then when I select it and copy it to another application (e.g. MS Word or WPS Office) I always get this ugly format with it:
I know I can "Keep text only" in MS Word (e.g. pressing Ctrl-T right after pasting) and similar options in other applications, but I wish there were a single hotkey, or if I could just convert all output in RStudio console to plain text by default (because I have no use for its formatting anyway).
IN Addins menu, there is an option to copy value/output to clipboard.
Please see clipr
Or you can capture console output and write output to clipboard.
to_clip_board <- function(x){
message(paste(
as.character(substitute(x)), "written to clipboard."
))
write.table(
paste0(capture.output(x),collapse = "\n"),
"clipboard",
col.names = FALSE,
row.names = FALSE
)
}
> to_clip_board(iris)
> to_clip_board(data.frame)
I just found a solution that works at least on my present OS, Linux Mint (19.3): Just select text and click with middle mouse button to the place (e.g. in WPS Office or LibreOffice) where you want to copy-paste the selected text. It will instantly copy and paste the text without formatting. (If you want to copy first, click with middle mouse button on the selected text, and then click again with middle mouse button to the place where you want it pasted.)
Others have said that the Ctrl + Shift + V should paste without formatting too, but that didn't work for me. This combination is supposed to also work on Windows in many applications. Otherwise for Windows you can download PureText that makes copy-paste without formatting super easy.
(In retrospect I realize this is not necessarily an R or RStudio question, but rather a more general OS clipboard issue. Nonetheless I needed it for R only, so I'll leave the question unchanged: there might be better and more general R-specific solutions in the future, such as making all console output plain text.)
When opening .rmd files in RStudio 3.3.2, they show up as completely empty. There is text if I open using Notepad or if I open on another machine. What is going on?
RMD file in question
I had a similar issue with older R files that opened as empty. It turned out that RStudio didn't use the correct encoding as default and therefore wasn't able to read the file (presented the file as empty).
You can make sure that you are using the correct encoding by:
Opening the file in RStudio as you normally would (the file will be empty)
Navigate to File -> Reopen with Encoding...
Select UTF-8 and click OK
UTF-8 will most likely be the encoding you need. You can also choose to set this as the default for all source files.
This issue was also addressed on RStudio Support
In RStudio go to:
Tools
Global Setting
Left hand side "Code"
a. under "Saving" - Default text econding: change to UTF-8
save #Richard N mentioned, save the files with "UTF-8" encoding. Will solve the issue.
Incase you saved the files without encoding, use the open with encoding option under "Files" tab.
I'm currently attempting to convert some PCL files into PDF using GhostPCL (PCL6).
For the most part this works. However, there is an odd problem with some of the conversion. For some reason, PCL6 is not converting some logos where are at the top of our documents. The logo is of the format:
^[(25XABCDEFGHIJKLMNOPQ^[(3#^M
^[(25X^[&a+1.49RRSTUVWXYZ[\]^_`ab^[(3#^M
^[(25X^[&a+1.49Rcdefghijklmnopqrs^M
when viewing the PCL file in vim. When printing the file as a PCL file, the image prints out correctly, but when converting to pdf, the following takes it's place:
ABCDEFGHIJKLMNOPQ
RSTUVWXYZ[\]^_`ab
cdefghijklmnopqrs
I recognize that the format is meant to be matched against some sort of embedded image or font, but it has been really difficult trying to find useful documentation on PCL (so I can actually figure out what these characters mean) or the conversion process.
Can anyone offer some insight on how to approach the conversion? We will need these images/logos in the converted documents since they often contain disclaimer information as part of the image.
EDIT1: I've also attempted converting to postscript and printing then and the same behavior occurs.
EDIT2: When rendering the PCL file in a viewer, the same text shows up instead of the image. But when printing, the logo does show up. Strange...
EDIT3: To clarify, sending the PCL file to a printer directly does not seem to cause the problem (i.e, the logo does print correctly). It's only when I attempt to convert it to another file format that the problem occurs.
What happens when you try rendering the PCL input with Ghostscript ? Eg to the display device. If it doesn't render its not going to end up in a PDF either.
Have you tried printing the file to a PCL printer ?
If it works to a PCL printer, but not when rendering you can open a bug against ghostpcl. If it renders but does not end up in the PDF then you can open a bug against ghostspcl with the 'pdf writer' component.
Its possible that the logo is shown using a rasterop, this is a part of the PCL imaging model which has no counterpart in PDF and so cannot be reproduced. The result of using a rasterop with the PDF device is variable, sometimes it will do what you expect, often it will not.
Is there a way to display past commands in R/R Studio?? I know in R Studio there is a shortcut (CTRL+UP Arrow) that allows you to see past lines you have ran. But this shortcut only allows you to access only a single line, not a block of previously run code. Is there a package, or some way in R to display and select blocks of past code in R/R Studio?
Here you can find a description of the panes in R Studio, including the "history" pane.
There you can select several lines and paste them into the code.
Also, you can use the command savehistory() to save your history in a file you can the modify. If you want to choose the name of the file to be saved, use
savehistory(file = filename)
The same option is available in the basic R GUI (MS Windows), with "Save history" in the "File" menu (as a .RHistory file). Then, you can open it with any text editor and modify your history to make a script.
To see a specific number of lines, you can use history(25) (for 25 previous lines).