First, Happy New Year. I am grateful for RStudio and the entire R community. I reproduced your results. I think I have steps you can follow to reproduce the error.
What I suggest you try:
Create a project. Add a folder called 'test'. Below that add a subfolder called 'data'. Navigate to 'data' and set it as the working directory from the Files pane. Check that data is the current working directory with the getwd() command from the console. Navigate up one level to the test directory. Use the File / New / R Markdown command (I chose HTML). Delete everything from line 12 on (just below blank line following ## R Markdown). Insert an R code block. Inside the block add a getwd() statement. Save the .rmd file in the test folder (being creative I named it test.rmd). Use Ctrl-Enter to execute that one line. Now I get the "test" folder when getwd() is run from the source and the "data" folder is run from the console.
For what it's worth, now that I am aware of the problem I can check that my code and console point to the same folder. The headache for me was I was trying to debug a 'path not found' type of error. The code would trigger the error. I'd run the code successfully in the console. That was my debugging headache. If this is so hard to reproduce I wonder how often people are going to encounter it. What I'm trying to say is that I understand if you want to move onto more pressing topics.
Again thank you for your help.
P.S. You can ignore the text below. I wrote it on the journey to produce the error above. I may need it if you still can't reproduce the error.
I logged out of RStudio Cloud, closed my browser and opened a new browser window. I log in. I click on a Workspace named "Red Tortoise". Then I click on my "Deployed" project. For whatever reason (I suppose the last session settings are saved), The File directory is open to Cloud/project/PortfolioConstruction/data (in the right bottom pane) Via the console getwd() produces that result. In the right bottom File pane I move up one folder by clicking on PortfolioConstruction. I open an .rmd file I happen to have there. I insert a getwd() command into the rmd and execute just that line with ctrl-enter. It returns
"/cloud/project/PortfolioConstruction"
Executing getwd() in the console still produces
"/cloud/project/PortfolioConstruction/data"
So the screenshots. Open the project -
Immediately run getwd() from the console -
Move up one level in directory structure, open an .rmd file -
Insert getwd() at end of .rmd file, highlight it and press ctrl-enter -
As shown in the last screenshot the results of getwd() don't match. For good measure, I run getwd() again from the console to confirm -
I can generate this over and over. Pretty sure it's not related to one project or anything. I don't even remember how I made it happen the first time. Also, in playing with this, I also found that when I left the project with the Files pane showing "/cloud/project/PortfolioConstruction", and then reopened it the console still produces "/cloud/project/PortfolioConstruction/data"