When I use Sys.chmod(file,'777'), it seems that the permission is changed only for the owner, and not for all users, how can I do this?
Sys.chmod(file,'777')
Turn off umask's check Sys.chmodto get what you want:
Sys.chmod
Sys.chmod(file, "777", use_umask = FALSE)
Alternatively use systemdirectly:
system
system('chmod 777 file')