Issue with serve_site() r blogdown - r

I'm using blogdown and Hugo to generate a website.
I've created a new R project and have downloaded the theme using:
blogdown::new_site(dir = "Theme", theme = 'pacollins/hugo-future-imperfect-slim') and I can preview the template once downloaded. However, if I close R and then restart and I use the add-in "serve site" I get the following error message:
Error in site_root(config) :
Could not find config.toml / config.yaml under...
and then the directory that the config.toml file is saved in (and all of the rest of the theme files) are listed.
I can't understand what's changing between being able to preview the site in R Studio Viewer, then quitting R and restarting and it not being able to find the config file.
I did find this advice: https://github.com/rstudio/blogdown/issues/48 which suggests that my working directory is not the root directory of the website. There are two things I don't understand:
1) How can the the root directory and working directory work together okay when I initially download the theme, until I quit R and restart, and then they appear to not be the same?
2) How to I change the root directory of the website to fix the issue?
Thanks!

If you followed the blogdown's documentation to create a new site with the command "blogdown::new_site(dir="/your/website/dir")", it will set your working directory to "/your/website/dir".
When you restart R/Rstudio, your current working directory is reset (probably to your home directory). You can check the current working directory with getwd().
The solution is simply set up the working directory:
The simpler way is to execute setwd("/your/website/dir"), then you should be able to run blogdown::serve_site()
The recommended way is to create a Rstudio project at /your/website/dir with File-New Project-Existing Directory. It will create a .Rproj file under the root directory of your website. After that, you can "open project" and work on your website, then preview with serve_site().

Related

Can I change where RStudio saves snippets?

I would like to change where RStudio saves the r.snippets file that stores my code snippets. According to this site, RStudio should save to ~/.R/snippets/r.snippets. I use R_USER=C:/Users/JT/R in my Renviron.site file to set the location of ~. I think this code works, because when I check the location of ~ in RStudio I get:
> path.expand("~")
[1] "C:/Users/JT/R"
However, when I edit the snippets in RStudio it creates the r.snippets file in the folder C:\Users\JT\Documents\.R\snippets\. I want the r.snippets file to be saved in the folder C:\Users\JT\R\.R\snippets\.
Any ideas what I'm doing wrong? Thanks.
Over on the RStudio Community site this same question was asked as Can you change the directory the Rstudio looks for the r.snippets file?
Very helpful answer by RStudio employee kevinushey was:
While that directory isn't currently configurable, you might have luck
creating a symbolic link (or, on Windows, a junction point) to
re-route the snippets directory to another location.
tom_greenwood, the user who asked the question followed up with details of the steps he used:
1. Put you existing r.snippets file in the new directory on the shared drive. I called mine 'snippet files'
2. Delete the snippets directory which is inside the .R directory
3. Run cdm as an administrator.
4. Enter the command mklink /D "C:\Users\name.surname\Documents\.R\snippets" "T:\shared directory\snippet files"
5. Restart Rstudio.

Changing directories in Spyder 3.5

I just updated my copy of Spyder on my Windows XP desktop to Spyder 3.5. How do I change directories so that the working directory is the one (in a subfolder in My documents)in which I have my Python Script and .txt data files (e.g. for running a regression)?
I had the same problem. I'm using the latest Spyder. I wanted my files to be in other than my home directory. I tried setting the current directory in Preferences. My files still wound up in my home directory. I tried the "cd" command. It said that the current directory was the one I wanted, but still the files were written to my home directory.
So I saved my script file in the directory I wanted. Now my files go where I would like.

R set working directory to current folder

I am currently working on a joint project, with all the files stored in a Dropbox. To avoid changing the working directory every time we change something, we use the following code:
this.dir = dirname(parent.frame(2)$ofile)
setwd(this.dir)
This is working fine when sourcing the code in Rstudio, but we are looking for a solution that is working outside RStudio.
The team is working on Mac and Windows.
For Windows, locate the file "Rprofile.site". In there, there will be set the following command setwd("PATH_TO_WD")
The same goes for Mac, the file is usually located at /etc/R/ path.
Just change the setwd in that file and everytime you launch R, the working directory will be set to the directory you want.
EDIT: In my Windows computer, the file is located at "C:\Program Files\R\R-3.2.3\etc

Working directory error

I am working with PyCharm 4.04. Since I installed it, every time I open it, as default directory I get this:
C:\Users\Laura\AppData\Local\Temp\main.py1.tmp>cd
Which gives me an error when trying to use the console:
Error:Cannot start process, the path specified for working directory
is not a directory
But even if I change the directory, the message does not disappear.
The terminal, though, it does work and I can run projects, but I would like to use the console.
Another solution is to close the project, run rm -rf .idea and re-open it. Apparently Pycharm gets confused by some direct folder manipulation and doesn't reflect it properly in his .idea/*.xml files
I also got this error, and it got resolved by setting the default working directory. Follow the below path, and set the Working Directory to the folder where your code resides.
File > Settings > Build, Execution, Deployment > Console > Python Console > Working Directory ...
I finally solved the problem.
I think it all started because the first project that I opened with pycharm was in my "download" folder, so the working directory was automatically set to a temporal folder by default and allthough I moved the project to another folder and I manually changed the working directory from the terminal, it was not working.
The solution was creating a new project and giving a correct path to the new project. It seems very easy but it was not that obvious.
In the upper right corner click on small ▼ next to your main to run (look to the left from green right-pointing triangle)
Select Edit configurations.
In ▼ Python select the proper configuration name.
Look at the Configuration panel.
Fix items Script and Working directory.
pycharm
I had this same problem and just had to reinstall pycharm. It's a quickfix and I can't ensure it won't happen again.
I solved this by replacing all instances of the old filename and old directory with the new one in .idea/workspace.xml
It can be done with PyCharm running.
#user1068430 has the answer in the comments to the question:
When you open a project open the directory not a specific python file.
Instead of ~/Documents/myProject/main.py open ~/Documents/myProject
If you "open" the .py file then you'll have to set the working directory (File > Settings > Build, Execution, Deployment > Console > Python Console > Working Directory) every time. If you "open" the directory containing the .py file, then PyCharm will open and all of your .py files will be available in the left window. Select one of them and you're good to go.
i had the same issue, the error comes up when i want to upgrade my packages and when i run my project "this FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\youruser\AppData\Local\Temp\gen_py\3.7\__init__.py'" i found that the Temp file in C:\Users\youruser\AppData\Local was corrupt and it was fixed by deleting the "Temp" file, once deleted it will automatically create a new one with "gen_py" in it
To anyone with similar issues: Python interpreter virtual environment is where your python.exe sits. The working directory is where your script sits. To make everything easier, open a new project, scroll to location where you script is stored, and select. Click the interpreter option, click existing (if old one worked) or choose the python.exe. When asked, open the project in a new window, close old one to avoid confusion.
source = banging my head against the console for past few hours.
if the above mentioned solutions are not working, you can restart a new project.
file > New project...
then,
create a new project.

GitLab rendering the wrong README in Project & Public views

I'm using R markdown (README.Rmd) to knit/render to README.md at the top level of a project directory. GitLab (both in Project and Public views) chooses the .Rmd file to render vs the .md file and produces a visual mess instead of a nicely-formatted project description.
Is there any way to tell GitLab to ignore .Rmd files when picking the "right" one to use for the project/public view or am I left with a workflow that will mean keeping the README.Rmd in a separate directory then having the R project build process render and copy a knitted README.md to the top-level project directory?
This is a fresh install (this week) of a self-hosted instance of GitLab, but you can see it rendering the wrong README here.
I've reproduced this issue. I'll look into this tomorrow and make a PR for fixing this.

Resources