connect SQL server file (mdf) with R tool It's possible to connect SQL server file (mdf) with R tool in visual studio 2017? I tried that many times but the connection failed.

From visual studio2017, I want to connect R with Sql server database.
I created R project then from R (tools--&gt; Data --&gt; Add database connection --&gt; Attach database file) but connection failed.
I am assuming you are trying to use SQL Expess localDB. Since you did not give specific error messages my answer is also very generic.

Here is a good reading about LocadDB.  Introducing LocalDB, an improved SQL Express.

Check if you have LocalDB installed and what version by running this in a command window.

sqllocaldb.exe info MSSQLLocalDB


From books oniline: 


  Once installed, LocalDB is an instance of SQL Server Express that can
  create and open SQL Server databases. The system database files for
  the database are stored in the users' local AppData path which is
  normally hidden. For example
  C:\Users\\AppData\Local\Microsoft\Microsoft SQL Server Local
  DB\Instances\LocalDBApp1. User database files are stored where the
  user designates, typically somewhere in the C:\Users\\Documents\
  folder.


If it not installed you can install 2016 using this method.

Once you are confirmed that you have localDB installed and version is correct use this document Working with SQL Server LocalDB to create new database(files) or attach existing files. See section SQL Server Express LocalDB.