How do I change command promt to Git Bash for shell()-function

Hi

I have a problem with an internal r-package that we are using in the organization
I am using the function r shell() to move files by calling shell("cp ./data/file.rds ../other_dir/")
We are all stuck in Windows but by using Rstudio, installing git this command is correctly executed on almost all computers in the organisation.

However, for one colleague the command does not work as the shell-function calls the internal windows command promt.

By setting the terminal Environment to Git Bash in Rstudio we have forced the Terminal work with Git Bash but this does not solve the problem with shell()using the windows command promt.

Example:

shell("ls")
'ls' is not recognized as an internal or external command,
operable program or batch file.

Hi,

I suggest you use the built-in R functions for this instead, as they will adapt to the system they are operating on.

file.create(..., showWarnings = TRUE)
file.exists(...)
file.remove(...)
file.rename(from, to)
file.append(file1, file2)
file.copy(from, to, overwrite = recursive, recursive = FALSE,
          copy.mode = TRUE, copy.date = FALSE)
file.symlink(from, to)
file.link(from, to)
Sys.junction(from, to)

If you like to move a file, you can copy it using the file.copy function then remove the one on the old location by file.remove.

Hope this helps,
PJ

We did manage to solve the issue by identifying that Rtools40 was not in PATH for my colleague. Our solution was to put Rtools40 into the environment variable PATH and restart R.

However, we will switch to @pieterjanvcs solution

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.