Yes
We see R2 pilot Mace Windu's Jedi Starfighter in "R2 Come Home", an episode of The Clone Wars Not only does he do some pretty fancy flying (surviving a dogfight with Slave I ), he docks with a hyperspace ring and flies all the way to Coruscant.
He also flies a Y-Wing bomber in "Nomad Droids", a later episode, and even blows up some vulture droids:
scifi.stackexchange.com/users/31051/Jason Baker
Yes
In Revenge of the Sith
we see Obi-Wan's R7 unit take his Starfighter back to the Republic ship with a message for Commander Cody, tricking General Grievous into thinking he has left Utapau so he can surprise the Separatist forces.
scifi.stackexchange.com/users/57258/The Mandolorian
Yes In Revenge of the Sith Obi-Wan has his droid take control of the flying for a bit.
OBI-WAN:
All right, R4.
No, no.
Nothing too fancy.
and later he even says OBI-WAN:
Flying is for droids!
He has his droid fly the ship again on Utapau.
OBI-WAN
: Take the Fighter back to the ship In Empire Strikes Back
R2 also makes a suggestion about taking control of the ship.
LUKE: (into comlink)
Yes, R2?
R2 utters a soft, carefully phrased steam of whistles.
LUKE:
(into comlink, chuckling)
That's all right.
I'd like to keep it on manual control for a while.
The little droid lets out a defeated whimper.
Luke smiles, and continues on his course.
- Ep.
V script
So yes, droids can fly the ships they're mounted in, even without a pilot inside the cockpit.
scifi.stackexchange.com/users/54827/RedCaio
Also answered by this scifi exchange post.
Does R2D2 Try to Trick Luke in Episode V - Empire Strikes Back?
R2D2 could control Luke's X-Wing in Episode V.
scifi.stackexchange.com/users/45543/Mykewlname
The answer is yes.
There are a few examples for this.
One is an episode in The Clone Wars where R2-D2 even outmanoeuvred the slave one.
Another is in the films in The Empire Strikes Back .
There R2-D2 during the evacuation scene flies the X-Wing towards the landing zone and Luke.
scifi.stackexchange.com/users/38245/Thomas
During Empire Strikes Back, after leaving Hoth: R2, set a course for the Dagobah system Also, a droid can handle more G-Forces than a human,so outmaneuvering a bounty hunter was no big deal for him.
scifi.stackexchange.com/users/52970/Ronk
Yes.
In the new (canon) novelisation of Star Wars: The Empire Strikes back, we have the following passage, just after the Battle at Hoth.
A short distance farther sits your X-wing, a spaceship outfitted for one pilot and one droid.
R2 is in his place.
He’s the one who piloted it out here to the muster site, to wait for you.
The Empire Strikes Back
: So You Want to Be a Jedi?
scifi.stackexchange.com/users/20774/Valorum
In addition to the above examples of droids piloting starfighters, droids are also capable of piloting capital ships.
There are many examples of Separatist capital ships being piloted by droids in The Clone Wars , not to mention the scene at the beginning of Revenge of the Sith .
Further, some droids are starfighters, again, at the beginning of Revenge of the Sith .
Obviously, a droid that functions as a starfighter is capable of piloting itself, and is therefore capable of piloting a starfighter.
scifi.stackexchange.com/users/79814/Jimmy Crack Corn
I was wondering if astromech droids (like R2-D2) could fully control any unmanned ship they're mounted in.
Can astromech droids control and fly the ships they're mounted in?
scifi.stackexchange.com
<star-wars><droids>
scifi.stackexchange.com/questions/110592
scifi.stackexchange.com/users/28420/Ivo Beckers
Yes, it appears that astromech droids can fully control any unmanned ship that they're mounted in. There are examples of this in various Star Wars films. Yes, droids can fly ships they are docked into. There are many examples of this in the Star Wars films and the 'canon' series of novels, for example when Obi-Wan has his droid take over the flying in Revenge of the Sith. 
Yes - and they are very skilled pilots. For example R2 piloting Mace Windu's Starfighter in "R2 Come Home" from the Clone Wars. Yes - for example when Obi-Wan has his droid take control of the flying for a while. Yes - for example when R2 flies an X-Wing in the Empire Strikes Back. Yes - for example when R2 sets course for Dagobah in TESB. Droids can actually be better pilots than humans because they can handle greater G-forces. Yes - for example in the official Star Wars novels there is a mention of how R2 flies an X-Wing after the Battle at Hoth. Yes - and droids are also capable of piloting capital ships, for example in the opening scene of Revenge of the Sith.