How to change the color of output in powerlevel10k settings (.p10k.zsh)? - zsh

I was able to modify almost everything in the .p10k.zsh file except the output color, where exactly is it? This -> https://imgur.com/a/ULLZ6xt
How is it called in the file? Thanks a lot in advance!
I tried to find the parameter in the file but wasn't able to.

Related

Brand new to R for MBA class

Can someone give me any hint why I'm getting an error message here? If I run this code where it's not in gray, it runs. When I copy/paste it to the gray section, I get an error.
Again, brand new to R here, so I'm sure it's something obvious but trying to get through an assignment and stuck here.enter image description here
My guess from the picture (post your code next time not a picture) is that your working directory isn't where your file is located. Use setwd("your file path here") to specify to R where your file of interest is located.

Simplest way to create Renviron.site file

In my opinion the simplest way to create .Renviron file is to use usethis::edit_r_environ().
Is there any analogous command which can create .Renviron.site file ? I couldn't find that command. Or maybe you can figure out some other simply way to create .Renviron.site file ? Only ones I found were very involved and unclear.
Thanks guys
These files are plain text files. You can create them with any text editor that can create .txt files.
So, if the file doesn't already exist:
Open a plain text editor (such as RStudio or Notepad),
create a new
file (and add the desired content),
save it, e.g., as
<R_HOME>/etc/Renviron.site.
The locations where R is searching for these files are described in help("Startup").

R: importing data impossible (windows)

I used to work with R on my mac and never had any problems.
Now I would like to use it on my work computer (windows). The problem is I can't import any files to start working with them. I tried several options:
mydata<-read.table("c:/temp/myfile.csv",header=TRUE)
mydata<-read.csv("myfile.csv",header=TRUE)
mydata<-read.table("c:/myfile.csv",header=TRUE)
mydata<-read.table("Desktop/myfile.csv",header=TRUE)
I also tried to change / into \ in all variants above.
Nothing seems to work. R displays the command in red, sometimes with a comment "connection can't be opened" or "no such file or directory" (my translation from German).
I tried copying the file I want to open to a different location (desktop, c:, temp), but alas, nothing helps.
Do you have any ideas why I have this problem and how I can solve it? Thanks in advance.
There is a safer way to work with paths; just using file.path().
So, if you're trying to get a file in C:/temp/turtles.csv, then you'd use:
targetFile <- file.path('C:/', 'temp', 'turtles.csv')
read.csv( targetFile, header=TRUE )
Minor point since it showed up on Twitter; DO NOT USE PATHS THAT EXIST ONLY IN YOUR ENVIRONMENT.
Try to keep the data in a path either in or directly under where the script is.
You have three ways to do this with read.csv() function
To avoid inserting actual path you can do it simply nesting function
read.csv(file.choose(),header=TRUE)
it will open pop up for selecting your file just select file from directory
where you have saved it.
Now if you have to insert a path then just get actual location of your file
by
read.csv("C:\path\to\your\file\filename.csv",header=TRUE)
for Example
read.csv("C:\Users\Amway\Desktop\resources.csv",header=TRUE)
Best way is to have your own work space directory
so create a directory by your preferred name and just set that directory as a
R session work space by
setwd("C:\path\to\your\workspace directory\")
check your current directory by
getwd()
now if you want to read a file into R session just copy your file to work
space and just write
read.csv("resources.csv",header=TRUE)
So, it should be like this.
setwd("c:/mydir") # note / instead of \ in windows
Also.
MyData <- read.csv(file="c:/mydir/TheDataIWantToReadIn.csv", header=TRUE, sep=",")
Windows uses the other backslash.
https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/

Saving .R script File Using Script

I am using R Studio and I want to save my script (i.e., the upper left panel). However, the only ways that I can find to do it are by either clicking the blue floppy disk icon to save or using the drop down menu File > Save > name.R
Is there any way besides using these shortcuts to save the script to a .R file or is the shortcut the only way?
Thanks.
You can use rstudioapi::documentSave() to save the currently open script file to disk.
From the source documentation, one can see that it can be used in conjunction with the id returned with getActiveDocumentContext()$id to make sure the document saved is the one running the script.
For your intended use, try:
rstudioapi::documentSave(rstudioapi::getActiveDocumentContext()$id)
For future reference, here is the reference manual of rstudioapi:
https://cran.rstudio.com/web/packages/rstudioapi/rstudioapi.pdf
I'm not yet allowed to comment, but this refers to the comment above that this does not work with .rmd files:
rstudioapi::documentSave(rstudioapi::getActiveDocumentContext()$id)
I tried and in Rstudio Version 1.2.5042 it does seem to work.
Every new tab in R(created by ctrl+shift+n) can be independently saved by using ctrl+s in the respective tab. If you intend to rename the file though, you may do it as you would rename any file in windows(goto the file location and single click on the filename). Hope my answer was of some help!

Calling Skim from inside R

I'm making a simple line in r to automatically open my generated plots.
I output the plots to a file called "plots.pdf" in the same directory as my r file, and at the end i use this two lines to try to open it:
dir <- paste("/Applications/Skim.app/Contents/MacOS/Skim ",getwd(),"/plots.pdf",sep="")
system(dir)
Basically, dir concatenates the full path of the skim app and the full path of the generated plot.
If i run the string stored at dir in a shell it works perfect, it opens the pdf file in Skim, but when i run it with system() from inside R it doesn't work (Skim says 'The document “plots.pdf” could not be opened.').
I believe this is a very little mistake somewhere in the syntax regarding the absolute/relative paths, but haven't managed to find it... Any advice is welcome! (Or a better way to achieve the same)
I found a way to bypass that problem, i just changed the path to Skim for the 'open' command and i let the system to assign the default app for pdf viewing. So:
dir <- paste("open ",getwd(),"/plots.pdf",sep="")
And it works.

Resources