You are on page 1of 124

R Installation and Administration

Table of Contents
This is a guide to installation and administration for R.
This manual is for R, version 3.4.4 Patched (2018-03-19).
Copyright © 2001–2018 R Core Team
Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under
the conditions for verbatim copying, provided that the entire resulting derived work
is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another
language, under the above conditions for modified versions, except that this
permission notice may be stated in a translation approved by the R Core Team.

1 Obtaining R
Sources, binaries and documentation for R can be obtained via CRAN, the
“Comprehensive R Archive Network” whose current members are listed at
https://CRAN.R-project.org/mirrors.html.

1.1 Getting and unpacking the sources


The simplest way is to download the most recent R-x.y.z.tar.gz file, and unpack it
with
tar -xf R-x.y.z.tar.gz
on systems that have a suitable1 tar installed. On other systems you need to have the
gzip program installed, when you can use
gzip -dc R-x.y.z.tar.gz | tar -xf -
The pathname of the directory into which the sources are unpacked should not
contain spaces, as most make programs (and specifically GNU make) do not expect
spaces.
If you want the build to be usable by a group of users, set umask before unpacking so
that the files will be readable by the target group (e.g., umask 022 to be usable by all
users). Keep this setting of umask whilst building and installing.
If you use a recent GNU version of tar and do this as a root account (which on
Windows includes accounts with administrator privileges) you may see many warnings
about changing ownership. In which case you can use
tar --no-same-owner -xf R-x.y.z.tar.gz
and perhaps also include the option --no-same-permissions. (These options can also
be set in the TAR_OPTIONS environment variable: if more than one option is included
they should be separated by spaces.)

R Manual – User Manual Pag. 1


1.2 Getting patched and development versions
A patched version of the current release, ‘r-patched’, and the current development
version, ‘r-devel’, are available as daily tarballs and via access to the R Subversion
repository. (For the two weeks prior to the release of a minor (3.x.0) version,
‘r-patched’ tarballs may refer to beta/release candidates of the upcoming release,
the patched version of the current release being available via Subversion.)
The tarballs are available from https://stat.ethz.ch/R/daily. Download R-patched.tar.gz
or R-devel.tar.gz (or the .tar.bz2 versions) and unpack as described in the previous
section. They are built in exactly the same way as distributions of R releases.

1.2.1 Using Subversion and rsync


Sources are also available via https://svn.R-project.org/R/, the R Subversion repository. If
you have a Subversion client (see https://subversion.apache.org/), you can check out
and update the current ‘r-devel’ from https://svn.r-project.org/R/trunk/ and
the current ‘r-patched’ from ‘https://svn.r-project.org/R/branches/R-x-y-branch/’
(where x and y are the major and minor number of the current released version of R).
E.g., use
svn checkout https://svn.r-project.org/R/trunk/ path
to check out ‘r-devel’ into directory path (which will be created if necessary). The
alpha, beta and RC versions of an upcoming x.y.0 release are available from
‘https://svn.r-project.org/R/branches/R-x-y-branch/’ in the four-week period
prior to the release.
Note that ‘https:’ is required2, and that the SSL certificate for the Subversion server
of the R project should be recognized as from a trusted source.
Note that retrieving the sources by e.g. wget -r or svn export from that URL will not
work (and will give a error early in the make process): the Subversion information is
needed to build R.
The Subversion repository does not contain the current sources for the recommended
packages, which can be obtained by rsync or downloaded from CRAN. To use rsync to
install the appropriate sources for the recommended packages, run ./tools/rsync-
recommended from the top-level directory of the R sources.
If downloading manually from CRAN, do ensure that you have the correct versions of the
recommended packages: if the number in the file VERSION is ‘x.y.z’ you need to
download the contents of ‘https://CRAN.R-project.org/src/contrib/dir’, where
dir is ‘x.y.z/Recommended’ for r-devel or x.y-patched/Recommended for r-patched,
respectively, to directory src/library/Recommended in the sources you have unpacked.
After downloading manually you need to execute tools/link-recommended from the top
level of the sources to make the requisite links in src/library/Recommended. A suitable
incantation from the top level of the R sources using wget might be (for the correct value
of dir)
wget -r -l1 --no-parent -A\*.gz -nd -P src/library/Recommended \
https://CRAN.R-project.org/src/contrib/dir
./tools/link-recommended

Pag. 2 R Manual – User Manual


2 Installing R under Unix-alikes
R will configure and build under most common Unix and Unix-alike platforms including
‘cpu-*-linux-gnu’ for the ‘alpha’, ‘arm’, ‘hppa’, ‘ix86’, ‘m68k’, ‘mips’, ‘mipsel’,
‘powerpc’, ‘s390’, ‘sparc’, and ‘x86_64’ CPUs, ‘x86_64-apple-darwin’, ‘i386-sun-
solaris’ and ‘sparc-sun-solaris’ as well as perhaps (it is tested less frequently on
these platforms) ‘i386-apple-darwin’, ‘i386-*-freebsd’, ‘x86_64-*-freebsd’,
‘i386-*-netbsd’, ‘x86_64/*-openbsd’ and ‘powerpc-ibm-aix6*’
In addition, binary distributions are available for some common Linux distributions and
for macOS (formerly OS X and Mac OS). See the FAQ for current details. These are
installed in platform-specific ways, so for the rest of this chapter we consider only
building from the sources.
Cross-building is not possible: installing R builds a minimal version of R and then runs
many R scripts to complete the build.

2.1 Simple compilation


First review the essential and useful tools and libraries in Essential and useful other
programs under a Unix-alike, and install those you want or need. Ensure that the
environment variable TMPDIR is either unset (and /tmp exists and can be written in and
scripts can be executed from) or points to the absolute path to a valid temporary
directory (one from which execution of scripts is allowed) which does not contain spaces.3
Choose a directory to install the R tree (R is not just a binary, but has additional data sets,
help files, font metrics etc). Let us call this place R_HOME. Untar the source code. This
should create directories src, doc, and several more under a top-level directory: change
to that top-level directory (At this point North American readers should consult Setting
paper size.) Issue the following commands:
./configure
make
(See Using make if your make is not called ‘make’.) Users of Debian-based 64-bit systems4
may need
./configure LIBnn=lib
make
Then check the built system works correctly by
make check
Failures are not necessarily problems as they might be caused by missing functionality,
but you should look carefully at any reported discrepancies. (Some non-fatal errors are
expected in locales that do not support Latin-1, in particular in true C locales and non-
UTF-8 non-Western-European locales.) A failure in tests/ok-errors.R may indicate
inade-quate resource limits (see Running R).
More comprehensive testing can be done by
make check-devel
or
make check-all

R Manual – User Manual Pag. 3


see file tests/README and Testing a Unix-alike Installation for the possibilities of doing
this in parallel. Note that these checks are only run completely if the recommended
packages are installed.
If the configure and make commands execute successfully, a shell-script front-end called
R will be created and copied to R_HOME/bin. You can link or copy this script to a place
where users can invoke it, for example to /usr/local/bin/R. You could also copy the
man page R.1 to a place where your man reader finds it, such as /usr/local/man/man1. If
you want to install the complete R tree to, e.g., /usr/local/lib/R, see Installation.
Note: you do not need to install R: you can run it from where it was built.
You do not necessarily have to build R in the top-level source directory (say, TOP_SRCDIR).
To build in BUILDDIR, run
cd BUILDDIR
TOP_SRCDIR/configure
make
and so on, as described further below. This has the advantage of always keeping your
source tree clean and is particularly recommended when you work with a version of R
from Subversion. (You may need GNU make to allow this, and you will need no spaces in
the path to the build directory. It is unlikely to work if the source directory has previously
been used for a build.)
Now rehash if necessary, type R, and read the R manuals and the R FAQ (files FAQ or
doc/manual/R-FAQ.html, or https://CRAN.R-project.org/doc/FAQ/R-FAQ.html which
always has the version for the latest release of R).
Note: if you already have R installed, check that where you installed R replaces or comes
earlier in your path than the previous installation. Some systems are set up to have
/usr/bin (the standard place for a system installation) ahead of /usr/local/bin (the
default place for installation of R) in their default path, and some do not have
/usr/local/bin on the default path.

2.2 Help options


By default HTML help pages are created when needed rather than being built at install
time.
If you need to disable the server and want HTML help, there is the option to
build HTML pages when packages are installed (including those installed with R). This is
enabled by the configure option --enable-prebuilt-html. Whether R CMD INSTALL
(and hence install.packages) pre-builds HTML pages is determined by looking at the R
installation and is reported by R CMD INSTALL --help: it can be overridden by specifying
one of the INSTALL options --html or --no-html.
The server is disabled by setting the environment variable R_DISABLE_HTTPD to a non-
empty value, either before R is started or within the R session before HTML help
(including help.start) is used. It is also possible that system security measures will
prevent the server from being started, for example if the loopback interface has been
disabled. See ?tools::startDynamicHelp for more details.

Pag. 4 R Manual – User Manual


2.3 Making the manuals
There is a set of manuals that can be built from the sources,
‘fullrefman’
Printed versions of all the help pages for base and recommended packages (around
3500 pages).
‘refman’
Printed versions of the help pages for selected base packages (around 2000 pages)
‘R-FAQ’
R FAQ
‘R-intro’
“An Introduction to R”.
‘R-data’
“R Data Import/Export”.
‘R-admin’
“R Installation and Administration”, this manual.
‘R-exts’
“Writing R Extensions”.
‘R-lang’
“The R Language Definition”.
To make these (with ‘fullrefman’ rather than ‘refman’), use
make pdf to create PDF versions
make info to create info files (not ‘refman’ nor ‘fullrefman’).
You will not be able to build any of these unless you have texi2any version 5.1 or later
installed, and for PDF you must have texi2dvi and texinfo.tex installed (which are part
of the GNU texinfo distribution but are, especially texinfo.tex, often made part of the
TeX package in re-distributions). For historical reasons, the path to texi2any can be set
by macro ‘MAKEINFO’ in config.site (makeinfo is nowadays a link to texi2any).
The PDF versions can be viewed using any recent PDF viewer: they have hyperlinks that can
be followed. The info files are suitable for reading online with Emacs or the
standalone GNU info program. The PDF versions will be created using the paper size
selected at configuration (default ISO a4): this can be overridden by setting R_PAPERSIZE on
the make command line, or setting R_PAPERSIZE in the environment and using make -e. (If
re-making the manuals for a different paper size, you should first delete the
file doc/manual/version.texi. The usual value for North America would be ‘letter’.)
There are some issues with making the PDF reference manual, fullrefman.pdf or
refman.pdf. The help files contain both ISO Latin1 characters (e.g. in text.Rd) and upright
quotes, neither of which are contained in the standard LaTeX Computer Modern fonts. We
have provided four alternatives:
times
(The default.) Using standard PostScript fonts, Times Roman, Helvetica and Courier. This
works well both for on-screen viewing and for printing. One disadvantage is that the
Usage and Examples sections may come out rather wide: this can be overcome by using
in addition either of the options inconsolata (on a Unix-alike only if found by
configure) or beramono, which replace the Courier monospaced font by Inconsolata or
Bera Sans mono respectively. (You will need a recent version of the appropriate LaTeX
5
package inconsolata or bera installed.)

R Manual – User Manual Pag. 5


Note that in most LaTeX installations this will not actually use the standard fonts for
PDF, but rather embed the URW clones NimbusRom, NimbusSans and (for Courier, if
used) NimbusMon.
This needs LaTeX packages times, helvetic and (if used) courier installed.
lm
Using the Latin Modern fonts. These are not often installed as part of a TeX distribution,
but can obtained from https://www.ctan.org/tex-archive/fonts/ps-type1/lm/ and
mirrors. This uses fonts rather similar to Computer Modern, but is not so good on-
screen as times.
cm-super
Using type-1 versions of the Computer Modern fonts by Vladimir Volovich. This is a
large installation, obtainable from https://www.ctan.org/tex-archive/fonts/ps-
type1/cm-super/ and its mirrors. These type-1 fonts have poor hinting and so are
nowhere near as readable on-screen as the other three options.
ae
A package to use composites of Computer Modern fonts. This works well most of the
time, and its PDF is more readable on-screen than the previous two options. There are
three fonts for which it will need to use bitmapped fonts, tctt0900.600pk,
tctt1000.600pk and tcrm1000.600pk. Unfortunately, if those files are not available,
Acrobat Reader will substitute completely incorrect glyphs so you need to examine the
logs carefully.
The default can be overridden by setting the environment variable R_RD4PDF. (On Unix-
alikes, this will be picked up at install time and stored in etc/Renviron, but can still be
overridden when the manuals are built, using make -e.) The usual6 default value
for R_RD4PDF is ‘times, inconsolata, hyper’: omit ‘hyper’ if you do not want
hyperlinks (e.g. for printing the manual) or do not have LaTeX package hyperref, and omit
‘inconsolata’ if you do not have LaTeX package inconsolata installed.
Further options, e.g for hyperref, can be included in a file Rd.cfg somewhere on your
LaTeX search path. For example, if you prefer the text and not the page number in the
table of contents to be hyperlinked use
\ifthenelse{\boolean{Rd@use@hyper}}{\hypersetup{linktoc=section}}{}
or
\ifthenelse{\boolean{Rd@use@hyper}}{\hypersetup{linktoc=all}}{}
to hyperlink both text and page number.
Ebook versions of most of the manuals in one or both of .epub and .mobi formats can be
made by running in doc/manual one of
make ebooks
make epub
make mobi
This requires ebook-convert from Calibre (http://calibre-ebook.com/download), or
from most Linux distributions. If necessary the path to ebook-convert can be set as make
macro EBOOK to by editing doc/manual/Makefile (which contains a commented value
suitable for macOS).

Pag. 6 R Manual – User Manual


2.4 Installation
To ensure that the installed tree is usable by the right group of users, set
umask appropriately (perhaps to ‘022’) before unpacking the sources and throughout the
build process.
After
./configure
make
make check
(or, when building outside the source, TOP_SRCDIR/configure, etc) have been completed
successfully, you can install the complete R tree to your system by typing
make install
A parallel make can be used (but run make before make install). Those using
GNU make 4.0 or later may want to use make -j n -O to avoid interleaving of output.
This will install to the following directories:
prefix/bin or bindir
the front-end shell script and other scripts and executables
prefix/man/man1 or mandir/man1
the man page
prefix/LIBnn/R or libdir/R
all the rest (libraries, on-line help system, …). Here LIBnn is usually ‘lib’, but may
be ‘lib64’ on some 64-bit Linux systems. This is known as the R home directory.
where prefix is determined during configuration (typically /usr/local) and can be set
by running configure with the option --prefix, as in
./configure --prefix=/where/you/want/R/to/go
where the value should be an absolute path. This causes make install to install the R
script to /where/you/want/R/to/go/bin, and so on. The prefix of the installation
directories can be seen in the status message that is displayed at the end of configure. The
installation may need to be done by the owner of prefix, often a root account.
You can install into another directory tree by using
make prefix=/path/to/here install
at least with GNU or Solaris make (but not some older Unix makes).
More precise control is available at configure time via options: see configure --help for
details. (However, most of the ‘Fine tuning of the installation directories’ options are not
used by R.)
Configure options --bindir and --mandir are supported and govern where a copy of
the R script and the man page are installed.
The configure option --libdir controls where the main R files are installed: the default is
‘eprefix/LIBnn’, where eprefix is the prefix used for installing architecture-dependent
files, defaults to prefix, and can be set via the configure option --exec-prefix.
Each of bindir, mandir and libdir can also be specified on the make install command
line (at least for GNU make).

R Manual – User Manual Pag. 7


The configure or make variables rdocdir and rsharedir can be used to install the system-
independent doc and share directories to somewhere other than libdir. The C header files
can be installed to the value of rincludedir: note that as the headers are not installed into
a subdirectory you probably want something like rincludedir=/usr/local/include/R-
3.4.4.
If you want the R home to be something other than libdir/R, use rhome: for example
make install rhome=/usr/local/lib64/R-3.4.4
will use a version-specific R home on a non-Debian Linux 64-bit system.
If you have made R as a shared/static library you can install it in your system’s library
directory by
make prefix=/path/to/here install-libR
where prefix is optional, and libdir will give more precise control.7 However, you
should not install to a directory mentioned in LDPATHS (e.g./usr/local/lib64) if you
intend to work with multiple versions of R, since that directory may be given precedence
over the lib directory of other R installations.
make install-strip
will install stripped executables, and on platforms where this is supported, stripped
libraries in directories lib and modules and in the standard packages.
Note that installing R into a directory whose path contains spaces is not supported, and
some aspects (such as installing source packages) will not work.
To install info and PDF versions of the manuals, use one or both of
make install-info
make install-pdf
Once again, it is optional to specify prefix, libdir or rhome (the PDF manuals are
installed under the R home directory). (make install-info needs Perl installed if there
is no command install-info on the system.)
More precise control is possible. For info, the setting used is that of infodir
(default prefix/info, set by configure option --infodir). The PDF files are installed into
the R doc tree, set by the make variable rdocdir.
A staged installation is possible, that it is installing R into a temporary directory in order to
move the installed tree to its final destination. In this case prefix (and so on) should
reflect the final destination, and DESTDIR should be used: see
https://www.gnu.org/prep/standards/html_node/DESTDIR.html.
You can optionally install the run-time tests that are part of make check-all by
make install-tests
which populates a tests directory in the installation.

Pag. 8 R Manual – User Manual


2.5 Uninstallation
You can uninstall R by
make uninstall
optionally specifying prefix etc in the same way as specified for installation.
This will also uninstall any installed manuals. There are specific targets to uninstall info
and PDF manuals in file doc/manual/Makefile.
Target uninstall-tests will uninstall any installed tests, as well as removing the
directory tests containing the test results.
An installed shared/static libR can be uninstalled by
make prefix=/path/to/here uninstall-libR

2.6 Sub-architectures
Some platforms can support closely related builds of R which can share all but the
executables and dynamic objects. Examples include builds under Linux and Solaris for
different CPUs or 32- and 64-bit builds.
R supports the idea of architecture-specific builds, specified by adding ‘r_arch=name’ to
the configure line. Here name can be anything non-empty, and is used to name
subdirectories of lib, etc, include and the package libs subdirectories. Example names
from other software are the use of sparcv9 on Sparc Solaris and 32 by gcc on ‘x86_64’
Linux.
If you have two or more such builds you can install them over each other (and for 32/64-bit
builds on one architecture, one build can be done without ‘r_arch’). The space savings can
be considerable: on ‘x86_64’ Linux a basic install (without debugging symbols) took 74Mb,
and adding a 32-bit build added 6Mb. If you have installed multiple builds you can select
which build to run by
R --arch=name
and just running ‘R’ will run the last build that was installed.
R CMD INSTALL will detect if more than one build is installed and try to install packages with
the appropriate library objects for each. This will not be done if the package has an
executable configure script or a src/Makefile file. In such cases you can install for extra
builds by
R --arch=name CMD INSTALL --libs-only pkg1 pkg2 …
If you want to mix sub-architectures compiled on different platforms (for example ‘x86_64’
Linux and ‘i686’ Linux), it is wise to use explicit names for each, and you may also need to
set libdir to ensure that they install into the same place.
When sub-architectures are used the version of Rscript in e.g. /usr/bin will be the last
installed, but architecture-specific versions will be available in e.g./usr/lib64/R/bin/
exec${R_ARCH}. Normally all installed architectures will run on the platform so the architecture
of Rscript itself does not matter. The executable Rscript will run the R script, and at that
time the setting of the R_ARCH environment variable determines the architecture which is run.
When running post-install tests with sub-architectures, use
R --arch=name CMD make check[-devel|all]
to select a sub-architecture to check.
R Manual – User Manual Pag. 9
Sub-architectures are also used on Windows, but by selecting executables within the
appropriate bin directory, R_HOME/bin/i386 or R_HOME/bin/x64. For backwards compatibi-
lity there are executables R_HOME/bin/R.exe and R_HOME/bin/Rscript.exe: these will run
an executable from one of the subdirectories, which one being taken first from the R_ARCH
8
environment variable, then from the --arch command-line option and finally from the
installation default (which is 32-bit for a combined 32/64 bit R installation).

2.6.1 Multilib
For some Linux distributions9, there is an alternative mechanism for mixing 32-bit and 64-
bit libraries known as multilib. If the Linux distribution supports multilib, then parallel
builds of R may be installed in the sub-directories lib (32-bit) and lib64 (64-bit). The build
to be run may then be selected using the setarch command. For example, a 32-bit build
may be run by
setarch i686 R
The setarch command is only operational if both 32-bit and 64-bit builds are installed. If
there is only one installation of R, then this will always be run regardless of the
architecture specified by the setarch command.
There can be problems with installing packages on the non-native architecture. It is a
good idea to run e.g. setarch i686 R for sessions in which packages are to be installed,
even if that is the only version of R installed (since this tells the package installation code
the architecture needed).
There is a potential problem with packages using Java, as the post-install for a ‘i686’
RPM on ‘x86_64’ Linux reconfigures Java and will find the ‘x86_64’ Java. If you know
where a 32-bit Java is installed you may be able to run (as root)
export JAVA_HOME=<path to jre directory of 32-bit Java>
setarch i686 R CMD javareconf
to get a suitable setting.
When this mechanism is used, the version of Rscript in e.g. /usr/bin will be the last
installed, but an architecture-specific version will be available in e.g. /usr/lib64/R/bin.
Normally all installed architectures will run on the platform so the architecture
of Rscript does not matter.

2.7 Other Options


There are many other installation options, most of which are listed by configure --help.
Almost all of those not listed elsewhere in this manual are either standard autoconf
options not relevant to R or intended for specialist uses by the R developers.
One that may be useful when working on R itself is the option --disable-byte-
compiled-packages, which ensures that the base and recommended packages are not
byte-compiled. (Alternatively the (make or environment) variable R_NO_BASE_COMPILE can
be set to a non-empty value for the duration of the build.)
Option --with-internal-tzcode makes use of R’s own code and copy of the Olson
database for managing timezones. This will be preferred where there are issues with the
system implementation, usually involving times after 2037 or before 1916.

Pag. 10 R Manual – User Manual


An alternative time-zone directory10 can be used, pointed to by environment variable
TZDIR: this should contain files such as Europe/London. On most OSes the system
timezone was deduced correctly, but if necessary it can be set as the value of
environment variable TZ. (OSes which do not follow the documentation of
/etc/localtime as a symbolic link will have problems: this includes recent Debian-based
Linuxen and RHEL/Centos 6 (but not 7).)

2.7.1 OpenMP Support


By default configure searches for suitable options11 for OpenMP support for the C, C++98,
FORTRAN 77 and Fortran compilers.
Only the C result is currently used for R itself, and only if MAIN_LD/DYLIB_LD were not
specified. This can be overridden by specifying
R_OPENMP_CFLAGS
Use for packages has similar restrictions (involving SHLIB_LD and similar: note that as
FORTRAN 77 code is normally linked by the C compiler, both need to support OpenMP)
and can be overridden by specifying some of
SHLIB_OPENMP_CFLAGS
SHLIB_OPENMP_CXXFLAGS
SHLIB_OPENMP_FCFLAGS
SHLIB_OPENMP_FFLAGS
Setting to an empty value will disable OpenMP for that compiler (and configuring
with --disable-openmp will disable all detection12 of OpenMP). The configure detection
test is to compile and link a standalone OpenMP program, which is not the same as
compiling a shared object and loading it into the C program of R’s executable. Note that
overridden values are not tested.
2.7.2 C++ Support
C++ is not used by R itself, but support is provided for installing packages with C++ code
via make macros defined in file etc/Makeconf (and with explanations in file config.site):
CXX
CXXFLAGS
CXXPICFLAGS
CXXSTD
CXX98
CXX98STD
CXX98FLAGS
CXX98PICFLAGS
CXX11
CXX11STD
CXX11FLAGS
CXX11PICFLAGS
CXX14
CXX14STD
CXX14FLAGS
CXX14PICFLAGS
CXX17
CXX17STD
CXX17FLAGS
CXX17PICFLAGS
R Manual – User Manual Pag. 11
The macros CXX etc are those used by default for C++ code. configure will attempt to set
the rest suitably, choosing for CXX11STD a suitable flag such as -std=c++11 for C++11
support. Similarly, configure will if possible choose for CXX14STD a flag13 such as -std=c++14
for C++14 support and -std=c++1z for support for the forthcoming C++17 standard. The
inferred values can be overridden in file config.site or on the configure command line:
user-supplied values will be tested compiling some C++11/14/17 code.
R versions 3.1.0 to 3.3.3 used CXX1X rather than CXX11, and these forms are deprecated but
still accepted.
14
It may be that there is no suitable flag for C++11 support, in which case a different compiler
could be selected for CXX11 and its corresponding flags. Likewise, a different compiler can be
specified for C++14 support with CXX14 and for C++17 support with CXX17. Some compilers15
by default assume a later standard than C++98 whereas the latter is assumed by some
packages. So users of GCC 6 might like to specify
CXX='g++ -std=gnu++98'
CXX11=g++
CXX11STD='-std=c++11'
CXX14=g++
CXX14STD='-std=c++14'
The -std flag is supported by the GCC, clang, Intel and Solaris compilers (the latter from
version 12.4). Currently accepted values are (plus some synonyms)
g++: c++98 gnu++98 c++11 gnu+11 c++14 gnu++14 c++1z gnu++1z
Intel: gnu+98 c++11 c++14 (from 16.0) c++17 (from 17.0)
Solaris: c++03 c++11 c++14 (from 12.5)
(Those for clang++ are not documented, but seem to be based on g++.) Versions 4.3.x to
4.8.x of g++ accepted flag -std=c++0x with partial support16 for C++11: this is currently still
accepted as a deprecated synonym for -std=c++11. (At least for versions 4.8.x it has
sufficient support to be picked by configure.) Option -std=c++14 was introduced in version
5.x.
‘Standards’ for g++ starting with ‘gnu’ enable ‘GNU extensions’: what those are is
hard to track down.
For the use of C++11 and later in R packages see the ‘Writing R Extensions’ manual.

2.8 Testing an Installation


Full post-installation testing is possible only if the test files have been installed with
make install-tests
which populates a tests directory in the installation.
If this has been done, two testing routes are available. The first is to move to the home
directory of the R installation (as given by R.home()) and run
cd tests
## followed by one of
../bin/R CMD make check
../bin/R CMD make check-devel
../bin/R CMD make check-all
and other useful targets are test-BasePackages and test-Recommended to run tests of
the standard and recommended packages (if installed) respectively.
Pag. 12 R Manual – User Manual
This re-runs all the tests relevant to the installed R (including for example code in the package
vignettes), but not for example the ones checking the example code in the manuals nor
making the standalone Rmath library. This can occasionally be useful when the operating
environment has been changed, for example by OS updates or by substituting the BLAS
(see Shared BLAS).
Parallel checking of packages may be possible: set the environment variable
TEST_MC_CORES to the maximum number of processes to be run in parallel. This affects
both checking the package examples (part of make check) and package sources (part of
make check-devel and make check-recommended). It does require a make command
which supports the make -j n option: most do but on Solaris you need to select GNU
make or dmake. Where parallel checking of package sources is done, a log file
pngname.log is left in the tests directory for inspection.
Alternatively, the installed R can be run, preferably with --vanilla. Then
Sys.setenv(LC_COLLATE = "C", LC_TIME = "C", LANGUAGE = "en")
tools::testInstalledBasic("both")
tools::testInstalledPackages(scope = "base")
tools::testInstalledPackages(scope = "recommended")
runs the basic tests and then all the tests on the standard and recommended packages.
These tests can be run from anywhere: the basic tests write their results in
the tests folder of the R home directory and run fewer tests than the first approach: in
particular they do not test things which need Internet access — that can be tested by
tools::testInstalledBasic("internet")
These tests work best if diff (in Rtools*.exe for Windows users) is in the path.
It is possible to test the installed packages (but not their package-specific tests)
by testInstalledPackages even if make install-tests was not run.
Note that the results may depend on the language set for times and messages: for
maximal similarity to reference results you may want to try setting (before starting the R
session)
LANGUAGE=en
and use a UTF-8 or Latin-1 locale.

R Manual – User Manual Pag. 13


3 Installing R under Windows
The bin/windows directory of a CRAN site contains binaries for a base distribution and a
large number of add-on packages from CRAN to run on 32- or 64-bit Windows (Windows
7 and later are tested; XP is known to fail some tests) on ‘ix86’ and ‘x86_64’ CPUs.
Your file system must allow long file names (as is likely except perhaps for some network-
mounted systems). If it doesn’t also support conversion to short name equivalents (a.k.a.
DOS 8.3 names), then R must be installed in a path that does not contain spaces.
Installation is via the installer R-3.4.4patched-win.exe. Just double-click on the icon and
follow the instructions. When installing on a 64-bit version of Windows the options will
include 32- or 64-bit versions of R (and the default is to install both). You can uninstall R
from the Control Panel.
Note that you will be asked to choose a language for installation, and that choice applies
to both installation and un-installation but not to running R itself.
See the R Windows FAQ for more details on the binary installer.

3.1 Building from source


R can be built as either a 32-bit or 64-bit application on Windows: to build the 64-bit
application you need a 64-bit edition of Windows: such an OS can also be used to build 32-bit R.
The standard installer combines 32-bit and 64-bit builds into a single executable which can
then be installed into the same location and share all the files except the .exe and .dll files
and some configuration files in the etc directory.
Building is only tested in a 8-bit locale: using a multi-byte locale (as used for CJK languages) is
unsupported and may not work (the scripts do try to select a ‘C’ locale; Windows may not
honour this).
NB: The build process is currently being changed to require external binary distributions
of third-party software. Their location is set using macro EXT_LIBS with default
setting $(LOCAL_SOFT); the $(LOCAL_SOFT) macro defaults to $(R_HOME)/extsoft. This
directory can be populated using make rsync-extsoft. The location can be overridden
by setting EXT_LIBS to a different path in src/gnuwin32/MkRules.local. A suitable
collection of files can also be obtained from https://CRAN.R-project.org/bin/windows/
extsoft or https://www.stats.ox.ac.uk/pub/Rtools/libs.html.

3.1.1 Getting the tools


If you want to build R from the sources, you will first need to collect, install and test an
extensive set of tools. See The Windows toolset (and perhaps updates in https://CRAN.R-
project.org/bin/windows/Rtools/) for details.
The Rtools*.exe executable installer described in The Windows toolset also includes
some source files in addition to the R source as noted below. You should run it first, to
obtain a working tar and other necessities. Choose a “Full installation”, and install the
extra files into your intended R source directory, e.g. C:/R. The directory name should not
contain spaces. We will call this directory R_HOME below.

Pag. 14 R Manual – User Manual


3.1.2 Getting the source files
You need to collect the following sets of files:
 Get the R source code tarball R-3.4.4.tar.gz from CRAN. Open a command window
(or another shell) at directory R_HOME, and run
 tar -xf R-3.4.4.tar.gz
to create the source tree in R_HOME. Beware: do use tar to extract the sources
rather than tools such as WinZip. If you are using an account with administrative
privileges you may get a lot of messages which can be suppressed by
tar --no-same-owner -xf R-3.4.4.tar.gz
or perhaps better, set the environment variable TAR_OPTIONS to the value
‘--no-same-owner --no-same-permissions’.
It is also possible to obtain the source code using Subversion; see Obtaining R for details.
 If you are not using a tarball you need to obtain copies of the recommended packages
from CRAN. Put the .tar.gz files in R_HOME/src/library/Recommended and run make
link-recommended. If you have an Internet connection, you can do this automatically
by running in R_HOME/src/gnuwin32
make rsync-recommended
 The binary distributions of external software. Download
https://www.stats.ox.ac.uk/pub/Rtools/goodies/multilib/local323.zip
(or a more recent version if appropriate), create an empty directory, say c:/R/extsoft,
and unpack it in that directory by e.g.
unzip local323.zip -d c:/R/extsoft
 Make a local copy of the configuration rules by
cd R_HOME/src/gnuwin32
cp MkRules.dist MkRules.local
and edit MkRules.local, uncommenting EXT_LIBS and setting it to the appropriate
path (in our example c:/R/extsoft).
Look through the file MkRules.local and make any other changes needed: in
particular, this is where a 64-bit build is selected and the locations are set of external
software for ICU collation and the cairo-based devices.
The following additional item is normally installed by Rtools*.exe. If instead you choose to
do a completely manual build you will also need
 The Tcl/Tk support files are contained in Rtools*.exe. Please make sure you install the
right version: there is a 32-bit version and a 64-bit version. They should be installed
to R_HOME, creating directory Tcl there.

3.1.3 Building the core files


Set the environment variable TMPDIR to the absolute path to a writable directory, with a
path specified with forward slashes and no spaces. (The default is /tmp, which may not be
useful on Windows.)
You may need to compile under a case-honouring file system: we found that a samba-
mounted file system (which maps all file names to lower case) did not work.

R Manual – User Manual Pag. 15


Open a command window at R_HOME/src/gnuwin32, then run
make all recommended vignettes
and sit back and wait while the basic compile takes place.
Notes:
 We have had reports that earlier versions of anti-virus software locking up the
machine, but not for several years. However, aggressive anti-virus checking such as
the on-access scanning of Sophos can slow the build down several-fold.
 You can run a parallel make by e.g.
make -j4 all
make -j4 recommended
make vignettes
but this is only likely to be worthwhile on a multi-core machine with ample memory,
and is not 100% reliable.
 It is possible (mainly for those working on R itself) to set the (make or environment)
variable R_NO_BASE_COMPILE to a non-empty value, which inhibits the byte-
compilation of the base and recommended packages.

3.1.4 Building the cairo devices


The devices based on cairographics (svg, cairo_pdf, cairo_ps and the type = "cairo"
versions of png, jpeg, tiff and bmp) are implemented in a separate DLL winCairo.dll
which is loaded when one of these devices is first used. It is not built by default, and
needs to be built (after make all) by make cairodevices.
To enable the building of these devices you need to install the static cairographics libraries
built by Simon Urbanek at https://www.rforge.net/Cairo/files/cairo-current-win.tar.gz. Set
the macro ‘CAIRO_HOME’ in MkRules.local. (Note that this tarball unpacks with a top-level
directory src/: ‘CAIRO_HOME’ needs to include that directory in its path.)

3.1.5 Using ICU for collation


It is recommended to build R to support ICU (International Components for
Unicode, http://site.icu-project.org/) for collation, as is commonly done on Unix-alikes.
Two settings are needed in MkRules.local,
# set to use ICU
# USE_ICU = YES
# path to parent of ICU headers
ICU_PATH = /path/to/ICU
The first should be uncommented and the second set to the top-level directory of a suitably
packaged binary build of ICU, for example that
at https://www.stats.ox.ac.uk/pub/Rtools/goodies/ICU_531.zip. Depending on the build, it may
be necessary to edit the macro ICU_LIBS.
Unlike on a Unix-alike, it is normally necessary to call icuSetCollate to set a locale before ICU
is actually used for collation, or set the environment variable R_ICU_LOCALE.

3.1.6 Support for libcurl

Pag. 16 R Manual – User Manual


libcurl version 7.28.0 or later is used to support curlGetHeaders and the "libcurl" methods
of download.file and url.
A suitable distribution can be found via https://www.stats.ox.ac.uk/pub/Rtools/libs.html and its
unpacked location should be specified in file MkRules.local.
For secure use of e.g. ‘https://’ URLs Windows users may need to specify the path to up-to-
date CA root certificates: see ?download.file.

3.1.7 Checking the build

You can test a build by running


make check
The recommended packages can be checked by
make check-recommended
Other levels of checking are
make check-devel
for a more thorough check of the R functionality, and
make check-all
for both check-devel and check-recommended.
If a test fails, there will almost always be a .Rout.fail file in the directory being checked
(often tests/Examples or tests): examine the file to help pinpoint the problem.
Parallel checking of package sources (part of make check-devel and make check-recommended) is
possible: see the environment variable TEST_MC_CORES to the maximum number of processes to
be run in parallel.

3.1.8 Building the manuals

The PDF manuals require texinfo 5.1 or later, and can be made by
make manuals
If you want to make the info versions (not including the Reference Manual), use
cd ../../doc/manual
make -f Makefile.win info
(all assuming you have pdftex/pdflatex installed and in your path).
See the Making the manuals section in the Unix-alike section for setting options such as the
paper size and the fonts used.
By default it is assumed that texinfo is not installed, and the manuals will not be built. The
comments in file MkRules.dist describe settings to build them. (Copy that file
to MkRules.local and edit it.) The texinfo 5.x package for use on Windows is available
at https://www.stats.ox.ac.uk/pub/Rtools/: you will also need to install Perl17

3.1.9 Building the Inno Setup installer


R Manual – User Manual Pag. 17
You need to have the files for a complete R build, including bitmap and Tcl/Tk support and the
manuals (which requires texinfo installed), as well as the recommended packages and Inno
Setup (see The Inno Setup installer).
Once everything is set up
make distribution
make check-all
will make all the pieces and the installer and put them in the gnuwin32/cran subdirectory,
then check the build. This works by building all the parts in the sequence:
rbuild (the executables, the FAQ docs etc.)
rpackages (the base packages)
htmldocs (the HTML documentation)
cairodevices (the cairo-based graphics devices)
recommended (the recommended packages)
vignettes (the vignettes in base packages:
only needed if building from an svn checkout)
manuals (the PDF manuals)
rinstaller (the install program)
crandir (the CRAN distribution directory, only for 64-bit builds)
The parts can be made individually if a full build is not needed, but earlier parts must be built
before later ones. (The Makefile doesn’t enforce this dependency—some build targets force a
lot of computation even if all files are up to date.) The first four targets are the default build if
just make (or make all) is run.
Parallel make is not supported and likely to fail.
If you want to customize the installation by adding extra packages, replace make rinstaller by
something like
make rinstaller EXTRA_PKGS='pkg1 pkg2 pkg3'
An alternative way to customize the installer starting with a binary distribution is to first make
an installation of R from the standard installer, then add packages and make other
customizations to that installation. Then (after having customized file MkRules,
possibly via MkRules.local, and having made R in the source tree)
in src/gnuwin32/installer run
make myR IMAGEDIR=rootdir
where rootdir is the path to the root of the customized installation (in double quotes if it
contains spaces or backslashes).
Both methods create an executable with a standard name such as R-3.4.4patched-
win.exe, so please rename it to indicate that it is customized. If you intend to distribute a
customized installer please do check that license requirements are met – note that the installer
will state that the contents are distributed under GPL and this has a requirement for you to
supply the complete sources (including the R sources even if you started with a binary
distribution of R, and also the sources of any extra packages (including their external software)
which are included).
The defaults for the startup parameters may also be customized. For example
make myR IMAGEDIR=rootdir MDISDI=1
will create an installer that defaults to installing R to run in SDI mode.
See src/gnuwin32/installer/Makefile for the names and values that can be set.

Pag. 18 R Manual – User Manual


The standard CRAN distribution of a 32/64-bit installer is made by first building 32-bit R (just
make 32-bit
is needed), and then (in a separate directory) building 64-bit R with the macro HOME32 set in
file MkRules.local to the top-level directory of the 32-bit build. Then the make
rinstaller step copies the files that differ between architectures from the 32-bit build as it
builds the installer image.

3.1.10 Building the MSI installer

It is also possible to build an installer for use with Microsoft Installer. This is intended for use
by sysadmins doing automated installs, and is not recommended for casual use.
It makes use of the Windows Installer XML (WiX) toolkit version 3.5 (or perhaps later,
untested) available from http://wixtoolset.org/. Once WiX is installed, set the path to its home
directory in MkRules.local.
You need to have the files for a complete R build, including bitmap and Tcl/Tk support and the
manuals, as well as the recommended packages. There is no option in the installer to customize
startup options, so edit etc/Rconsole and etc/Rprofile.site to set these as required.
Then
cd installer
make msi
which will result in a file with a name like R-3.4.4patched-win32.msi. This can be
double-clicked to be installed, but those who need it will know what to do with it (usually by
running msiexec /i with additional options). Properties that users might want to set from
the msiexec command line include ‘ALLUSERS’, ‘INSTALLDIR’ (something
like c:\Program Files\R\R-3.4.4patched) and ‘RMENU’ (the path to the ‘R’ folder
on the start menu) and ‘STARTDIR’ (the starting directory for R shortcuts, defaulting to
something like c:\Users\name\Documents\R).
The MSI installer can be built both from a 32-bit build of R (R-3.4.4patched-
win32.msi) and from a 64-bit build of R (R-3.4.4patched-win64.msi, optionally
including 32-bit files by setting the macro HOME32, when the name is R-3.4.4patched-
win.msi). Unlike the main installer, a 64-bit MSI installer can only be run on 64-bit Windows.
Thanks to David del Campo (Dept of Statistics, University of Oxford) for suggesting WiX and
building a prototype installer.

3.1.11 64-bit Windows builds

To build a 64-bit version of R you need a 64-bit toolchain: the only one discussed here is based
on the work of the MinGW-w64 project (http://sourceforge.net/projects/mingw-w64/, but
commercial compilers such as those from Intel and PGI could be used (and have been by R
redistributors).
Support for MinGW-w64 was developed in the R sources over the period 2008–10 and was first
released as part of R 2.11.0. The assistance of Yu Gong at a crucial step in porting R to

R Manual – User Manual Pag. 19


MinGW-w64 is gratefully acknowledged, as well as help from Kai Tietz, the lead developer of
the MinGW-w64 project.
Windows 64-bit is now completely integrated into the R and package build systems: a 64-bit
build is selected in file MkRules.local.

3.2 Testing an Installation


The Windows installer contains a set of test files used when building R.
The Rtools are not needed to run these tests. but more comprehensive analysis of errors will be
given if diff is in the path (and errorsAreFatal = FALSE is then not needed below).
Launch either Rgui or Rterm, preferably with --vanilla. Then run
Sys.setenv(LC_COLLATE = "C", LANGUAGE = "en")
library("tools")
testInstalledBasic("both")
testInstalledPackages(scope = "base", errorsAreFatal = FALSE)
testInstalledPackages(scope = "recommended", errorsAreFatal = FALSE)
runs the basic tests and then all the tests on the standard and recommended packages. These tests
can be run from anywhere: they write some of their results in the tests folder of the R home
directory (as given by R.home()), and hence may need to be run under the account used to install
R.
The results of example(md5sums) when testing tools will differ from the reference output as some
files are installed with Windows’ CRLF line endings.

4 Installing R under macOS

Pag. 20 R Manual – User Manual


R Manual – User Manual Pag. 21
4. LANGUAGES
4.1. Programming Languages
4.1.1. Hundreds of programming languages supported
In Visual Studio Code, we have support for almost every major programming language.
Several ship in the box, for example, JavaScript, TypeScript, CSS, and HTML but more rich
language extensions can be found in the VS Code Marketplace.
Here are eight of the most popular language extensions:

Python C/C++ C# Go
ms-python 8267.2K ms-vscode 6705.3K ms-vscode 5353.0K lukehoban 2831.2K
Linting, Debugging (multi- C/C++ IntelliSense, debugging, C# for Visual Studio Code Rich Go language support for
threaded, remote), Inte... and code browsing. (powered by OmniSharp). Visual Studio Code

Ruby Java Extension Pack PHP IntelliSense Rusty Code


rebornix 716.9K vscjava 659.9K felixfbecker 339.4K saviorisdead 86.9K
Advanced Autocompletion and Popula VS Code extensions for Everything you need for PHP Rust language integration for
Refactoring support f... Java development development. VSCode

Go to the Marketplace or use our integrated extension manager and search for your
desired programming language to find snippets, code completion/IntelliSense providers,
linters, debuggers and more.
Note: If you want to change the display language of VS Code (for example, to Chinese), see
the Display Language topic.
4.1.2. Language specific documentation
On this website, we have a number of topics outlining several of the common languages
supported by VS Code. These include: C++ - C# - CSS - Dockerfile - Go - HTML - Java -
JavaScript - JSON - Less -Markdown - PHP - Python - Sass - T-SQL - TypeScript.
Click on any linked item to get an overview of how to use VS Code in the context of that
language. Most language extensions also contain a summary of their core features in their
README.
4.1.3. Language features in VS Code
The richness of support varies across the different languages and their extensions:
 Syntax highlighting and bracket matching
 Smart completions (IntelliSense)
 Linting and corrections
 Code navigation (Go to Definition, Find All References)
 Debugging
 Refactoring

Pag. 22 R Manual – User Manual


4.1.4. Changing the language for the selected file
In VS Code, we default the language support for a file based on its filename extension.
However, at times you may wish to change language modes, to do this click on the language
indicator - which is located on the right hand of the Status Bar. This will bring up the Select
Language Mode drop-down where you can select another language for the current file.

Tip: You can get the same drop-down by running the Change Language Mode command
(Ctrl+K M).

4.1.5. Language Id
VS Code associates a language mode with a specific language identifier so that various VS
Code features can be enabled based on the current language mode.
A language identifier is often (but not always) the lowercased programming language name.
Note that casing matters for exact identifier matching ('Markdown' != 'markdown').
Unknown language files have the language identifier plaintext.
You can see the list of currently installed languages and their identifiers in the Change
Language Mode (Ctrl+K M) drop-down.

You can find a list of known identifiers in the language identifier reference.
4.1.6. Adding a file extension to a language
You can add new file extensions to an existing language with the files.associations
setting.
For example, the setting below adds the .myphp file extension to the php language identifier:
"files.associations": {
"*.myphp": "php"
}

R Manual – User Manual Pag. 23


IntelliSense (Ctrl+Space) will show you the available language identifiers.

4.1.7. Next Steps


Now you know that VS Code has support for the languages you care about. Read on...
 Code Navigation - Peek and Go to Definition and more
 Debugging - This is where VS Code really shines

4.1.8. Common Questions


Q: Can I contribute my own language service?
A: Yes you can! Check out the example language server in the VS Code Extension
Authoring documentation.
Q: What if I don't want to create a full language service, can I reuse existing TextMate
bundles?
A: Yes, you can also add support for your favorite language through TextMate colorizers.
See Themes, Snippets, and Colorizers topic in the Extension Authoring section to learn how
to integrate TextMate .tmLanguage syntax files into VS Code.
Q: Can I map additional file extensions to a language?
A: Yes, with the files.associations setting you can map file extensions to an existing
language either globally or per workspace.
Here is an example that will associate more file extensions to the PHP language:

"files.associations": {
"*.php4": "php",
"*.php5": "php"
}

You can also configure full file paths to languages if needed. The following example
associates all files in a folder somefolder to PHP:
"files.associations": {
"**/somefolder/*.*": "php"
}

Note that the pattern is a glob pattern that will match on the full path of the file if it contains
a / and will match on the file name otherwise.

Pag. 24 R Manual – User Manual


4.2. JavaScript in VS Code
Visual Studio Code provides IntelliSense, debugging, and powerful editor features for
JavaScript. VS Code uses the JavaScript language service to make authoring JavaScript easy.
In addition to syntactical features like format, format on type and outlining, you also get
language service features such as Peek, Go to Definition, Find all References, and Rename
Symbol.

4.2.1. IntelliSense
VS Code IntelliSense is intelligent code completion, parameter info, and member lists. VS
Code provides IntelliSense using TypeScript type declaration (typings) files (for example,
node.d.ts) to provide metadata about the JavaScript based frameworks you are consuming
in your application. Type declaration files are written in TypeScript so they can express the
data types of parameters and functions, allowing VS Code to provide a rich IntelliSense
experience.
Thanks to a feature called Automatic Type Acquisition you as a user do not have to worry
about these type declaration files. VS Code will install them automatically for you.

R Manual – User Manual Pag. 25


For the details of how JavaScript IntelliSense works, including being based on type inference,
JsDoc annotations, TypeScript declarations, and mixing JavaScript and TypeScript projects,
see the JavaScript language service documentation.
When type inference does not provide the desired information, type information may be
provided explicitly with JSDoc annotations. This document describes the JSDoc annotations
currently supported. In addition to objects, methods, and properties, the JavaScript
IntelliSense window also provides basic word completion for the symbols in your file.
VS Code ships with the most stable version of the JavaScript language service. The same
language service powers both JavaScript and TypeScript, so if you want to use a newer
version, you can define the typescript.tsdk setting to point to a directory containing the
TypeScript tsserver.js file. See more details here.
4.2.2. Automatic Type Acquisition
VS Code JavaScript IntelliSense for third-party libraries and modules is powered by *.d.ts
type declaration (typings) files coming from the npmjs type declaration file repository and
requires npm, the Node.js package manager, included with the Node.js runtime.
In this image you can see IntelliSense, including the method signature, parameter info, and
the method's documentation, for a popular library called lodash.

Type declaration files are automatically downloaded and managed by Visual Studio Code for
packages listed in your project's package.json.
"dependencies": {
"lodash": "^4.17.0"
}

Pag. 26 R Manual – User Manual


If you are using Visual Studio Code 1.8+, you can alternately explicitly list packages to acquire
type declaration files for in your jsconfig.json.
"typeAcquisition": {
"include": [
"lodash"
]
}

Now when you require or import lodash, VS Code will use the automatically downloaded
type declaration files for the library to provide rich Intellisense. Most common JavaScript
libraries have type declaration files available. You can search for a library's type declaration
file package using the TypeSearch site.
4.2.2.1. Fixing NPM not installed warning for Automatic Type Acquisition
Automatic Type Acquisition (ATA) uses npm, the Node.js package manager, to install and
manage Type Declaration (typings) files. To ensure that Automatic Type Acquisition works
properly, first ensure that you have npm installed on your machine.
A quick check that npm is installed and available is to run npm --version from a terminal or
command prompt.
npm is installed with the Node.js runtime, which is available for download from Nodejs.org.
Install the current LTS (Long Term Support) version and the npm executable will be added by
default to your system path.
If you have npm installed but still see a warning message, you can explicitly tell VS Code
where npm is installed with the typescript.npm setting. This should be set to the full path
of the npm executable on your machine, and this does not have to match the version of npm
you are using to manage packages in your workspace. typescript.npm requires TypeScript
2.3.4+.
For example on Windows, you would add a path like this to your settings.json file:

"typescript.npm": "C:\\Program Files\\nodejs\\npm.cmd"

4.2.3. JavaScript Project (jsconfig.json)


The presence of a jsconfig.json file in a directory indicates that the directory is the root of a
JavaScript project. jsconfig.json specifies the root files and the options for the language
features provided by the JavaScript language service. For common setups a
jsconfig.json file is not required, however, there are situations when you will want to add
a jsconfig.json.
 Not all files should be in your JavaScript project (for example, you want to exclude some
files from showing IntelliSense). This situation is common with front-end and back-end
code.
 Your workspace contains more than one project context. In this situation, you should
add a jsconfig.json file at the root folder for each project.
 You are using the TypeScript compiler to down-level compile JavaScript source code.

R Manual – User Manual Pag. 27


4.2.3.1. Location of jsconfig.json
To define our code as a JavaScript project, create jsconfig.json at the root of your
JavaScript code as shown below. A JavaScript project is the source files of the project and
should not include the derived or packaged files (such as a dist directory).

In more complex projects, you may have more than one jsconfig.json file defined inside a
workspace. You will want to do this so that the source code in one project does not appear in
the IntelliSense of another project.
Illustrated below is a project with a client and server folder, showing two separate
JavaScript projects:

4.2.3.2. Writing jsconfig.json


Below is a simple template for jsconfig.json file which defines the JavaScript target to
be ES6 and the exclude attribute excludes the node_modules folder. You can copy and
paste this code into your jsconfig.json file.

{ "compilerOptions": { "target": "ES6" },


"exclude": [ "node_modules",
"**/node_modules/*" ] }

The exclude attribute tells the language service which files are and are not part of your
source code. If IntelliSense is slow, add folders to your exclude list (VS Code will prompt you
to do this if it detects slow completions). You will want to exclude files generated by a build
process (such as a dist directory). These files will cause suggestions to show up twice and
will slow down IntelliSense.
You can explicitly set the files in your project using the include attribute. If no include
attribute is present, then this defaults to including all files in the containing directory and
subdirectories. When a include attribute is specified, only those files are included.
Here is an example with an explicit include attribute:

{ "compilerOptions": { "target": "ES6" },


"include": [ "src/**/*" ] }

Pag. 28 R Manual – User Manual


The best practice, and least error prone route, is to use the include attribute with a
single src folder. Note that the file paths in exclude and include are relative to the location
of jsconfig.json.
See here for the full documentation of jsconfig.json.
Note: jsconfig.json is the same as a tsconfig.json file, only with allowJS set to true.
See the documentation for tsconfig.json here to see other available options.
4.2.4. Debugging
VS Code comes with great debugging support for JavaScript. Set breakpoints, inspect objects,
navigate the call stack, and execute code in the Debug Console. See more about
debugging here.
4.2.4.1. Debug Client Side
You can debug your client side code using a browser debugger such as Debugger for
Chrome, Debugger for Edge or Debugger for Firefox.
4.2.4.2. Debug Server Side
Debug Node.js in VS Code using the built-in debugger. Setup is easy and you can read a
tutorial for Node.js debugging here.

4.2.5. Type Checking and Quick Fixes for JavaScript Files


VS Code allows you to leverage some of TypeScript's advanced type checking and error
reporting functionality in regular JavaScript files. This is a great way to catch common
programming mistakes. These type checks also enable some exciting quickfixes for JavaScript,
including add missing import and add missing property.

R Manual – User Manual Pag. 29


TypeScript can infer types in .js files same as in .ts files. When types cannot be inferred,
they can be specified using JSDoc comments. You can read more about how TypeScript uses
JSDocs for JavaScript type checking here.
Type checking of JavaScript is optional and opt-in. Existing JavaScript validation tools such as
ESLint can be used alongside the new built-in type checking functionality.
You can get started with type checking a few different ways depending on your needs.
Per file
The easiest way to enable type checking in a JavaScript file is by adding // @ts-check to
the top of a file.

// @ts-check
let easy = 'abc'
easy = 123 // Error: Type '123' is not assignable to type 'string'

Using // @ts-check is a good approach if you just want to try type checking in a few files
but not yet enable it for an entire codebase.
Using a Setting
To enable type checking for all JavaScript files without changing any code, just
add "javascript.implicitProjectConfig.checkJs": true to your workspace or user
setti1 jhn67gs. This enables type checking for any JavaScript file that is not part of
a jsconfig.json or tsconfig.json project.

Pag. 30 R Manual – User Manual


You can opt individual files out of type checking with a // @ts-nocheck comment at the
top of the file:

// @ts-nocheck
let easy = 'abc'
easy = 123 // no error

You can also disable individual errors in a JavaScript file using a // @ts-ignore comment
on the line before the error:
let easy = 'abc'
// @ts-ignore
easy = 123 // no error

Using a JSConfig or TSConfig


To enable type checking for JavaScript files that are part of a jsconfig.json or
tsconfig.json, add "checkJs": true to the project's compiler options:
jsconfig.json:
{
"compilerOptions": {
"checkJs": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"checkJs": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

This enables type checking for all JavaScript files in the project. You can use // @ts-
nocheck to disable type checking per file.
JavaScript type checking requires TypeScript 2.3. If you are unsure what version of TypeScript
is currently active in your workspace, run the TypeScript: Select TypeScript Version
command to check. You must have a .js/.ts file open in the editor to run this command. If
you open a TypeScript file, the version appears in the lower right corner.

R Manual – User Manual Pag. 31


Global Variables and Type Checking
Let's say that you are working in legacy JavaScript code that uses global variables or non-
standard DOM APIs:
window.onload = function() {
if (window.webkitNotifications.requestPermission() === CAN_NOTIFY) {
window.webkitNotifications.createNotification(null, 'Woof!', ' ').show()
} else { alert('Could not notify') }
}

If you try to use // @ts-check with the above code, you'll see a number of errors about the
use of global variables:
1. Line 2 - Property 'webkitNotifications' does not exist on type
'Window'.
2. Line 2 - Cannot find name 'CAN_NOTIFY'.
3. Line 3 - Property 'webkitNotifications' does not exist on type
'Window'.
If you want to continue using // @ts-check but are confident that these are not actual
issues with your application, you have to let TypeScript know about these global variables.
To start, create a jsconfig.json at the root of your project:

{ "compilerOptions": { },
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

Then reload VS Code to make sure the change is applied. The presence of a jsconfig.json
lets TypeScript know that your Javascript files are part of a larger project.
Now create a globals.d.ts file somewhere your workspace:

interface Window {
webkitNotifications: any;
}

declare var CAN_NOTIFY: number;

d.ts files are type declarations. In this case, globals.d.ts lets TypeScript know that a
global CAN_NOTIFY exists and that a webkitNotifications property exists on window. You
can read more about writing d.ts here. d.ts files do not change how JavaScript is
evaluated, they are used only for providing better JavaScript language support.
4.2.6. Linters
A linter is a tool that provides warnings for suspicious looking code. VS Code supports linters
through extensions. Linters provide warnings, errors, and light bulb actions.
VS Code provides support for JavaScript linters, including ESLint, JSHint and StandardJS. If
enabled, the JavaScript code is validated as you type and you can navigate to reported
problems and fix them inside VS Code.

Pag. 32 R Manual – User Manual


Tip: In the above example, the error comes from eslint. Error messages will be prefixed
(see above [eslint]) by the originator of the message. Error messages from the JavaScript
language service are prefixed js.
Tip: You can disable default JavaScript validation by setting "javascript.validate.enable":
false in your settings.

TSLint stylelint jshint Flow Language Suppor...


eg2 4557.2K shinnn 599.4K dbaeumer 590.2K flowtype 201.5K
Integrates JSHint into VS Code.
TSLint for Visual Studio Code Modern CSS/SCSS/Less linter Flow support for VS Code
JSHint is a linte...

Tip: This list is dynamically queried from the VS Code Marketplace. Read the description
and reviews to decide if the extension is right for you.
A linter extension may require an external tool. The steps below show how to setup ESLint.
The process is similar for other linters.
1. Install the linter globally or inside the workspace folder that contains the JavaScript
code to be validated. For example, using npm install -g eslint.
2. Install the ESLint extension.
3. Create a .eslintrc.json file in the root of your workspace to configure the linter. You
can use eslint --init to create an initial version of the .eslintrc.json file.
a Tip: You get IntelliSense and hovering inside the .eslintrc.json file.
Tip: The linter is enabled after installation. You can disable a linter with the corresponding
.enable setting. For ESLint, this would be setting "eslint.enable" : false.
It is recommended that you enable the linter rules that warn about undefined and unused
variables. To do this, put the following options in your .eslintrc.json file.

"no-undef": 1,
"no-unused-vars": 1,

R Manual – User Manual Pag. 33


You can also control when a linter runs with the linter .run setting. The two options are the
default onType after each key stroke and onSave after you save your file.
Here are a few useful resources when using ESLint.
 Complete list of ESLint Rules
 Configuring ESLint
 Getting Started with ESLint

4.2.7. Snippets
VS Code has several built-in snippets that will come up as you type or you can press
Ctrl+Space (Trigger Suggest) and you will see a context specific list of suggestions.

Tip: You can add in your own snippets for JavaScript. See User Defined Snippets to find out
how.
You may not want to show snippets. You can disable them by setting
editor.snippetSuggestions to "none" in your settings file. If you'd like to see snippets,
you can specify the order relative to suggestions; at the top ("top"), at the bottom
("bottom"), or inlined ordered alphabetically ("inline"). The default is "inline".
You can enable tab completions with editor.tabCompletion setting. After typing the prefix
of a snippet, press Tab to insert it.
4.2.8. Use Next Generation JavaScript
4.2.8.1. Run Babel inside VS Code
The Babel transpiler turns ES6 files into readable ES5 JavaScript with Source Maps. You can
easily integrate Babel into your workflow by adding the configuration below to your
tasks.json file (located under the workspace's .vscode folder). The group setting makes
this task the default Task: Run Build Task gesture. isBackground tells VS Code to keep
running this task in the background. To learn more, go to Tasks.

{ "version": "2.0.0",
"tasks": [
{ "label": "watch",
"command": "${workspaceFolder}/node_modules/.bin/babel",
"args": ["src", "--out-dir", "lib", "-w", "--source-maps"],
"type": "shell",
"group": { "kind": "build", "isDefault": true },
"isBackground": true }
]
}

Pag. 34 R Manual – User Manual


Once you have added this, you can start Babel with the Ctrl+Shift+B (Run Build Task)
command and it will compile all files from the src directory into the lib directory.
a Tip: For help with Babel CLI see the instructions here. The example above uses the CLI option.

4.2.8.2. Use the TypeScript Compiler


One of the key features TypeScript provides is the ability to use the latest JavaScript language
features, and emit code that can execute in JavaScript runtimes that don't yet understand
those newer features. With JavaScript using the same language service, it too can now take
advantage of this same feature.
The TypeScript compiler tsc can down-level compile JavaScript files from ES6 to another
language level. Configure the jsconfig.json with the desired options and then use the –p
argument to make tsc use your jsconfig.json file, e.g. tsc -p jsconfig.json to down-
level compile.
Read more about the compiler options for down level compilation here.
4.2.9. Formatting
As with other languages, you can format your JavaScript code in VS Code.

VS Code provides several formatting settings for JavaScript. They can all be found in the
javascript.format settings namespace.
// Defines space handling after a comma delimiter
"javascript.format.insertSpaceAfterCommaDelimiter": boolean,
// Defines space handling after a semicolon in a for statement
"javascript.format.insertSpaceAfterSemicolonInForStatements": boolean,
// Defines space handling after a binary operator
"javascript.format.insertSpaceBeforeAndAfterBinaryOperators": boolean,
// Defines space handling after keywords in control flow statement
"javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": boolean,

R Manual – User Manual Pag. 35


// Defines space handling after function keyword for anonymous functions
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": boolean,
// Defines space handling after opening and before closing non empty parenthesis
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": boolean,
// Defines space handling after opening and before closing non empty brackets
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": boolean,
// Defines whether an open brace is put onto a new line for functions or not
"javascript.format.placeOpenBraceOnNewLineForFunctions": boolean,
// Defines whether an open brace is put onto a new line for control blocks or not
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": boolean,

4.2.10. Auto Imports


Automatic imports speed up coding by helping you find available symbols and automatically
adding imports for them.
Just start typing to see suggestions for all available JavaScript symbols in your current
project.

If you choose one of the suggestion from another file or module, VS Code will automatically add
an import for it. In this example, VS Code adds an import for Hercules to the top of the file:

Pag. 36 R Manual – User Manual


Auto imports requires TypeScript 2.6+ and are enabled by default. You can disable auto
imports by setting "typescript.autoImportSuggestions.enabled": false.
4.2.11. References CodeLens
The JavaScript references CodeLens displays an inline count of reference for classes, methods,
properties, and exported objects:

You can enable this by setting "javascript.referencesCodeLens.enabled": true.


Click on the reference count to quickly browse a list of references:

R Manual – User Manual Pag. 37


4.2.12. Popular Extensions
VS Code ships with excellent support for JavaScript but you can additionally install
debuggers, snippets, linters, and other JavaScript tools through extensions.

Debugger for Chrome TSLint Code Runner Angular v5 Snippets


msjsdiag 7169.1K eg2 4557.2K formulahendry 2901.6K johnpapa 2598.6K
Debug your JavaScript code TSLint for Visual Studio Run C, C++, Java, JS, PHP, Angular v5 snippets by John
in the Chrome browser,... Code Python, Perl, Ruby, Go... Papa

Tip: The extensions shown above are dynamically queried. Click on an extension tile above
to read the description and reviews to decide which extension is best for you. See more in
the Marketplace.
4.2.13. Next Steps
Read on to find out about:
 jsconfig.json - Detailed description of the jsconfig.json project file.
 IntelliSense - Learn more about IntelliSense and how to use it effectively for your
language.
 Debugging - Learn how to set up debugging for your application.
 Node.js - A walkthrough to create an Express Node.js application.
 TypeScript - VS Code has great support for TypeScript which brings structure and
strong typing to your JavaScript code.
Watch these introductory videos:
 Quick Tour using JavaScript - See a three-minute overview of using JavaScript in VS
Code.
 IntelliSense - Tutorial on IntelliSense with JavaScript.
 Debugging - Learn how to debug a Node.js application.

4.2.14. Common Questions


Q: Does VS Code support JSX and React Native?
A: VS Code supports JSX and React Native. You will get IntelliSense for React/JSX and
React Native from automatically downloaded type declaration (typings) files from the
npmjs type declaration file repository. Additionally, you can install the popular React Native
extension from the Marketplace.
React Native examples often use the experimental Object Rest/Spread operator. This is not
yet supported by VS Code. If you want to use it, it is recommended that you disable the built-
in syntax checking (see below).
To enable ES6 import statements for React Native, you need to set the
allowSyntheticDefaultImports compiler option to true. This tells the compiler to create
synthetic default members and you get IntelliSense. React Native uses Babel behind the
scenes to create the proper run-time code with default members. If you also want to do
debugging of React Native code then you can install the React Native Extension.

Pag. 38 R Manual – User Manual


Q: IntelliSense is not working for external libraries.
A: Automatic Type Acquisition works for dependencies downloaded by npm (specified
in package.json), Bower (specified in bower.json), and for many of the most common
libraries listed in your folder structure (i.e. jquery-3.1.1.min.js).
ES6 Style imports are not working.
When you want to use ES6 style imports but some type declaration (typings) files do not yet use ES6
style exports, then set the TypeScript compiler option allowSyntheticDefaultImports to
true.

{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
// This is the line you want to add
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

Q: Can I debug minified/uglified JavaScript?


A: Yes, you can. You can see this working using JavaScript source maps in the Node.js
Debugging topic.
Q: How do I disable Syntax Validation when using non ES6 constructs?
A: Some users want to use syntax constructs like the proposed Object Rest/Spread
Properties. However, these are currently not supported by VS Code's JavaScript language
service and are flagged as errors. For users who still want to use these future features, we
provide the javascript.validate.enable setting.
With javascript.validate.enable: false, you disable all built-in syntax checking. If you
do this, we recommend that you use a linter like ESLint to validate your source code. Since
VS Code's JavaScript support doesn't understand ES7 constructs, features like IntelliSense
might not be fully accurate.

R Manual – User Manual Pag. 39


4.3. Editing JSON with VS Code
JSON is a data format that is common in configuration files like package.json or
project.json. We also use it extensively in VS Code for our configuration files. When
opening a file that ends with .json, VS Code provides features out of the box to make it
simpler to write or modify the file's content.

4.3.1. IntelliSense & Validation


For properties and values, both for JSON data with and without a schema, we offer up
suggestions as you type with IntelliSense. You can also manually see suggestions with
the Trigger Suggestions command (Ctrl+Space). We also perform structural and value
verification based on an associated JSON schema giving you red squigglies.

4.3.1.1. Package and Project Dependencies


We also offer IntelliSense for specific value sets such as package and project dependencies
in package.json, project.json and bower.json.
4.3.2. Quick Navigation
JSON files can get pretty large and we support quick navigation to properties the Go to
Symbol command (Ctrl+Shift+O).

Pag. 40 R Manual – User Manual


4.3.3. Hovers
When you hover over properties and values for JSON data with or without schema, we will
provide additional context.

4.3.4. Formatting
You can format your JSON document using Shift+Alt+F or Format Document from the
context menu.
4.3.5. JSON with Comments
In addition to the default JSON mode following the JSON specification, VS Code also has
a JSON with Comments mode . This mode is used for the VS Code configuration files such
as settings.json, tasks.json or launch.json. When in the JSON with Comments
mode, you can use single line (//) as well as block comments (/* */) as used in JavaScript.
The current editor mode is indicated in the editor's Status Bar. Click on the mode indicator to
change the mode and to configure how file names and extensions are associated to modes.
4.3.5. JSON Schemas & Settings
To understand the structure of JSON files, we use JSON schemas. JSON schemas describe
the shape of the JSON file, as well as value sets, default values, and descriptions. The JSON
support shipped with VS Code supports JSON Schema Draft 6.
Servers like JSON Schema Store provide schemas for most of the common JSON based
configuration files. However, schemas can also be defined in a file in the VS Code workspace,
as well as the VS Code settings files.
The association of a JSON file to a schema can be done either in the JSON file itself using
the $schema attribute, or in the User or Workspace settings (File > Preferences > Settings)
under the property json.schemas.
VS Code extensions can also define schemas and schema mapping. That's why VS Code
already knows about the schema of some well known JSON files such as package.json,
bower.json and tsconfig.json.
4.3.5.1. Mapping in the JSON
In the following example, the JSON file specifies that its contents follow the CoffeeLint schema.

{
"$schema": "http://json.schemastore.org/coffeelint",
"line_endings": "unix"
}

Please note that this syntax is VS Code-specific and not part of the JSON Schema
specification. Adding the $schema key changes the JSON itself, which systems consuming
the JSON might not expect, for example, schema validation might fail. If this is the case, you
can use one of the other mapping methods.

R Manual – User Manual Pag. 41


4.3.5.1. Mapping in the User Settings
The following excerpt from User settings shows how .babelrc files are mapped to the
babelrc schema located on http://json.schemastore.org/babelrc.

"json.schemas": [
{
"fileMatch": [
"/.babelrc"
],
"url": "http://json.schemastore.org/babelrc"
},

Tip: Additionally to defining a schema for .babelrc, also make sure that .babelrc is
associated to the JSON language mode. This is also done in the settings using the
files.association array setting.
4.3.5.2. Mapping to a Schema in the Workspace
To map a schema that is located in the workspace, use a relative path. In this example, a file
in the workspace root called myschema.json will be used as the schema for all files ending
with .foo.json.

"json.schemas": [
{
"fileMatch": [
"/*.foo.json"
],
"url": "./myschema.json"
},

4.3.5.3. Mapping to a Schema Defined in Settings


To map a schema that is defined in the User or Workspace settings, use the schema property.
In this example, a schema is defined that will be used for all files named .myconfig.

"json.schemas": [
{
"fileMatch": [
"/.myconfig"
],
"schema": {
"type": "object",
"properties": {
"name" : {
"type": "string",
"description": "The name of the entry"
}
}
}
},

4.3.5.4. Mapping a Schema in an Extension


Schemas and schema associations can also be defined by an extension. Check out the
jsonValidation contribution point.

Pag. 42 R Manual – User Manual


4.3.5.5. Define Snippets in JSON Schemas
JSON schemas describe the shape of the JSON file, as well as value sets and default values
which are used by the JSON language support to provide completion proposals. If you are a
schema author and want to provide even more customized completion proposals, you can
also specify snippets in the schema. The following example shows a schema for a key binding
settings file defining a snippet:

{
"type": "array",
"title": "Keybindings configuration",
"items": {
"type": "object",
"required": ["key"],
"defaultSnippets": [
{
"label": "New keybinding",
"description": "Binds a key to a command for a given state",
"body": { "key": "$1", "command": "$2", "when": "$3" }
}
],
"properties": {
"key": {
"type": "string",
}
...
}
}
};

Use the property defaultSnippets to specify any number of snippets for the given JSON
object.
 label and description will be shown in the completion selection dialog. If no label is
provided, a stringified object representation of the snippet will be shown as label
instead.
 body is the JSON object that is stringified and inserted when the completion is selected
by the user. Snippet syntax can be used inside strings literals to define tabstops,
placeholders and variables. If a string starts with ^, the string content will be inserted as-
is, not stringified. You can use this to specify snippets for numbers and booleans.
Note that defaultSnippets is not part of the JSON schema spec but a VS Code specific
schema extension.

R Manual – User Manual Pag. 43


4.4. HTML programming in VS Code
Visual Studio Code provides basic support for HTML programming out of the box. There is
syntax highlighting, smart completions with IntelliSense, and customizable formatting. VS
Code also includes great Emmet support.
4.4.1. IntelliSense
As you type in HTML, we offer suggestions via HTML IntelliSense. In the image below you can
see a suggested HTML element closure </div> as well as a context specific list of suggested
elements.

We also offer up suggestions for elements, tags, some values (as defined in HTML5), Ionic
and AngularJS tags. Document symbols are also available for HTML, allowing you to quickly
navigate to DOM nodes by id and class name.
You can also work with embedded CSS and JavaScript. However, note that script and style
includes from other files are not followed, the language support only looks at the content of
the HTML file.
You can trigger suggestions at any time by pressing Ctrl+Space.
You can also control which built-in code completion providers are active. Override these in
your user or workspace settings if you prefer not to see the corresponding suggestions.

// Configures if the built-in HTML language suggests Angular V1 tags and properties.
"html.suggest.angular1": true,

// Configures if the built-in HTML language suggests Ionic tags, properties and values.
"html.suggest.ionic": true,

// Configures if the built-in HTML language suggests HTML5 tags, properties and values.
"html.suggest.html5": true

4.4.2. Close tags


Tag elements are automatically closed when > of the opening tag is typed.

Pag. 44 R Manual – User Manual


The matching closing tag is inserted when / of the closing tag is entered.

You can turn off autoclosing tags with the following setting:

"html.autoClosingTags": false

4.4.3. Color picker


The VS Code color picker UI is now available in HTML style sections.

4.4.4. Hover
Move the mouse over HTML tags or embedded styles and JavaScript to get more information
on the symbol under the cursor.

R Manual – User Manual Pag. 45


4.4.5. Validation
The HTML language support performs validation on all embedded JavaScript and CSS.
You can turn that validation off with the following settings:
// Configures if the built-in HTML language support validates embedded scripts.
"html.validate.scripts": true,

// Configures if the built-in HTML language support validates embedded styles.


"html.validate.styles": true

4.4.6. Formatting
To improve the formatting of your HTML source code, press Ctrl+K Ctrl+F and the selected
area will be reformatted.
The HTML formatter is based on js-beautify. The formatting options offered by that library
are surfaced in the VS Code settings:
 html.format.wrapLineLength: Maximum amount of characters per line.
 html.format.unformatted: List of tags that shouldn't be reformatted.
 html.format.contentUnformatted: List of tags, comma separated, where the content
shouldn't be reformatted.
 html.format.extraLiners: List of tags that should have an extra newline before
them.
 html.format.preserveNewLines: Whether existing line breaks before elements
should be preserved.
 html.format.maxPreserveNewLines: Maximum number of line breaks to be preserved in
one chunk.
 html.format.endWithNewline: End with a newline.
 html.format.indentInnerHtml: Indent <head> and <body> sections.
 html.format.wrapAttributes: Wrapping strategy for attributes:
o auto: Wrap when the line length is exceeded
o force: Wrap all attributes, except first
o force-aligned: Wrap all attributes, except first, and align attributes
o force-expand-multiline: Wrap all attributes
Tip: The formatter does not format the tags listed in the html.format.unformatted and
html.format.contentUnformatted settings. Embedded JavaScript is formatted unless
'script' tags are excluded.
The Marketplace has several alternative formatters to choose from. If you want to use a
different formatter, define "html.format.enable": false in your settings to turn off the
built-in formatter.

Pag. 46 R Manual – User Manual


4.4.7. Emmet snippets
We support Emmet snippet expansion. Emmet abbreviations are listed along with other
suggestions and snippets in the editor auto-completion list.

a Tip: See the HTML section of the Emmet cheat sheet for valid abbreviations.
If you'd like to use HTML Emmet abbreviations with other languages, you can associate one
of the Emmet modes (such as css, html) with other languages with the
emmet.includeLanguages setting. The setting takes a language id and associates it with
the language id of an Emmet supported mode.
For example, to use Emmet HTML abbreviations inside JavaScript:

{ "emmet.includeLanguages": { "javascript": "html" }


}

We also support User Defined Snippets.


4.4.8. HTML extensions
Install an extension to add more functionality. Go to the Extensions view (Ctrl+Shift+X)
and type 'html' to see a list of relevant extensions to help with creating and editing HTML.

IntelliSense for CSS... HTML Snippets HTML CSS Support HTMLHint


Zignd 2139.4K abusaidm 1617.7K ecmel 1220.0K mkaufman 232.1K
CSS class name completion for Full HTML tags including CSS support for HTML VS Code integration for
the HTML class attr... HTML5 Snippets documents HTMLHint - A Static Code ...

Tip: Click on an extension tile above to read the description and reviews to decide which
extension is best for you. See more in the Marketplace.
4.4.9. Next Steps
Read on to find out about:
 CSS, Less and Sass - VS Code has first class support for CSS including Less and Sass.
 Emmet - Learn about VS Code's powerful built-in Emmet support.

4.4.10. Common Questions


Q: Does VS Code have HTML preview?
A: No, VS Code doesn't have built-in support for HTML preview but there are extensions
available in the VS Code Marketplace. Open the Extensions view (Ctrl+Shift+X) and
search on 'live preview' or 'html preview' to see a list of available HTML preview extensions.

R Manual – User Manual Pag. 47


4.5. CSS, Sass and Less
Visual Studio Code has built-in support for editing style sheets in CSS .css, Sass .scss and
Less .less. In addition, you can install an extension for greater functionality.

IntelliSense for CSS... HTML CSS Support stylelint Beautify css/sass/sc...


Zignd 2139.6K ecmel 1220.2K shinnn 600.6K michelemelluso 227.2K
CSS class name completion for CSS support for HTML Modern CSS/SCSS/Less Beautify css, sass and less
the HTML class attr... documents linter code (extension for V...

Tip: Click on an extension tile above to read the description and reviews to decide which
extension is best for you. See more in the Marketplace.
4.5.1. IntelliSense
VS Code has support for selectors, properties and values. Use Ctrl+Space to get a list of
context specific options.

Proposals contain extensive documentation, including a list of browsers that support the
property. To see the full description text of the selected entry, use Ctrl+Space.
4.5.2. Syntax coloring & color preview
As you type, there is syntax highlighting as well as in context preview of colors.

Pag. 48 R Manual – User Manual


Clicking on a color preview will launch the integrated color picker which supports
configuration of hue, saturation and opacity.

Tip: You can trigger between different color modes by clicking on the color string at the
top of the picker.
You can hide VS Code's color previews by setting the following setting:

"css.colorDecorators.enable": false

4.5.3. Emmet snippets


Emmet abbreviation support is built into VS Code, suggestions are listed along with other
suggestions and snippets in the editor auto-completion list.
a Tip: See the CSS section of the Emmet cheat sheet for valid abbreviations.
VS Code also supports User Defined Snippets.
4.5.4. Syntax Verification & Linting
There is support for CSS version <= 2.1, Sass version <= 3.2 and Less version <= 2.3.
Note: You can disable VS Code's default CSS, Sass or Less validation by setting the
corresponding .validate User or Workspace setting to false.

"css.validate": false

4.5.5. Go to Symbol in file


You can quickly navigate to the relevant CSS symbol from any file by pressing Ctrl+Shift+O.
4.5.6. Hovers
Hovering over a selector or property will provide an HTML snippet that is matched by the CSS rule.

R Manual – User Manual Pag. 49


4.5.7. Go to Declaration and Find References
This is supported for Sass and Less variables in the same file. CSS variables per the draft
standards proposal are also supported.
a Note: Cross file references ('imports') are not resolved.
4.5.8. Transpiling Sass and Less into CSS
VS Code can integrate with Sass and Less transpilers through our integrated task runner. We
can use this to transpile .scss or .less files into .css files. Let's walk through transpiling a
simple Sass/Less file.
Step 1: Install a Sass or Less transpiler
For this walkthrough, let's use either the node-sass or less Node.js module.
Note: If you don't have Node.js and the NPM package manager already installed, you'll
need to do so for this walkthrough. Install Node.js for your platform. The Node Package
Manager (NPM) is included in the Node.js distribution. You'll need to open a new terminal
(command prompt) for npm to be on your PATH.

npm install -g node-sass less

Step 2: Create a simple Sass or Less file


Open VS Code on an empty folder and create a styles.scss or styles.less file. Place the
following code in that file:

$padding: 6px;

nav {
ul {
margin: 0;
padding: $padding;
list-style: none;
}

li { display: inline-block; }

a {
display: block;
padding: $padding 12px;
text-decoration: none;
}
}

For the Less version of the above file, just change $padding to @padding.
Note: This is a very simple example, which is why the source code is almost identical
between both file types. In more advanced scenarios, the syntaxes and constructs will be
much different.
Step 3: Create tasks.json
The next step is to set up the task configuration. To do this, run Tasks > Configure Tasks
and click Create tasks.json file from templates. In the selection dialog that shows up,
select Others.

Pag. 50 R Manual – User Manual


This will create a sample tasks.json file in the workspace .vscode folder. The initial version
of file has an example to run an arbitrary command. We will modify that configuration for
transpiling Sass/Less instead:

// Sass configuration
{ // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [ { "label": "Sass Compile",
"type": "shell",
"command": "node-sass styles.scss styles.css",
"group": "build" } ]
}

// Less configuration
{ // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [ { "label": "Less Compile",
"type": "shell",
"command": "lessc styles.less styles.css",
"group": "build" } ]
}

Step 4: Run the Build Task


As this is the only command in the file, you can execute it by pressing Ctrl+Shift+B (Run
Build Task). The sample Sass/Less file should not have any compile problems, so by running
the task all that happens is a corresponding styles.css file is created.
Since in more complex environments there can be more than one build task we prompt you
to pick the task to execute after pressing Ctrl+Shift+B (Run Build Task). In addition we
allow you to scan the output for compile problems (errors and warnings). Depending on the
compiler select an apropriate entry in the list to scan the tool output for errors and warnings.
If you don't want to scan the output select Never scan the build output from the presented
list.
At this point, you should see an additional file show up in the file list sample.html.
If you want to make the task the default build task to run execute Configure Default Build
Task... from the global Tasks menu and select the corresponding Sass or Less task from the
presented list.
Note: If your build fails or you see an error message such as "An output directory must be
specified when compiling a directory", be sure the filenames in your tasks.json match
the filenames on disk. You can always test your build by running node-sass styles.scss
styles.css from the command line.
4.5.9. Automating Sass/Less compilation
Let's take things a little further and automate Sass/Less compilation with VS Code. We can do
so with the same task runner integration as before, but with a few modifications.
Step 1: Install Gulp and some plug-ins
We will use Gulp to create a task that will automate Sass/Less compilation. We will also use
the gulp-sass plug-in to make things a little easier. The Less plug-in is gulp-less.

R Manual – User Manual Pag. 51


We need to install gulp both globally (-g switch) and locally:

npm install -g gulp


npm install gulp gulp-sass gulp-less

Note: gulp-sass and gulp-less are Gulp plug-ins for the node-sass and lessc modules
we were using before. There are many other Gulp Sass and Less plug-ins you can use, as
well as plug-ins for Grunt.
You can test that your gulp installation was successful but typing gulp -v. You should see a
version displayed for both the global (CLI) and local installations.
Step 2: Create a simple Gulp task
Open VS Code on the same folder from before (contains styles.scss/styles.less and
tasks.json under the .vscode folder), and create gulpfile.js at the root.
Place the following code in the gulpfile.js file:
// Sass configuration
var gulp = require('gulp');
var sass = require('gulp-sass');

gulp.task('sass', function() {
gulp.src('*.scss')
.pipe(sass())
.pipe(gulp.dest(function(f) { return f.base; }))
});

gulp.task('default', ['sass'], function() {


gulp.watch('*.scss', ['sass']);
})

// Less configuration
var gulp = require('gulp');
var less = require('gulp-less');

gulp.task('less', function() {
gulp.src('*.less')
.pipe(less())
.pipe(gulp.dest(function(f) { return f.base; }))
});

gulp.task('default', ['less'], function() {


gulp.watch('*.less', ['less']);
})

What is happening here?


1. Our default gulp task first runs the sass or less task once when it starts up.
2. It then watches for changes to any Sass/Less file at the root of our workspace, for
example the current folder open in VS Code.
3. It takes the set of Sass/Less files that have changed and runs them through our
respective compiler, for example gulp-sass, gulp-less.
4. We now have a set of CSS files, each named respectively after their original Sass/Less
file. We then put these files in the same directory.

Pag. 52 R Manual – User Manual


Step 3: Run the gulp default task
To complete the tasks integration with VS Code, we will need to modify the task configuration
from before to run the default Gulp task we just created. You can either delete the
tasks.json file or empty it only keeping the "version": "2.0.0" property. Now execute
Run Task from the global Tasks menu. Observe that you are presented with a picker listing
the tasks defined in the gulp file. Select gulp: default to start the task. We allow you to scan
the output for compile problems. Depending on the compiler select an apropriate entry in
the list to scan the tool output for errors and warnings. If you don't want to scan the output
select Never scan the build output from the presented list. At this point, if you create
and/or modify Less or SASS files, you see the respective CSS files generated and/or changes
reflected on save. You can also enable Auto Save to make things even more streamlined.
If you want to make the gulp: default task the default build task executed when pressing
Ctrl+Shift+B run Configure Default Build Task from the global Tasks menu and select
gulp: default from the presented list.
Step 4: Terminate the gulp default Task
The gulp: default task runs in the background and watches for file changes to Markdown
files. If you want to stop the task, you can use the Terminate Running Task from the
global Tasks menu.
4.5.10. Customizing CSS, Sass and Less Settings
You can configure the following lint warnings as User and Workspace Settings.
The validate setting allows you turn off the built-in validation. You would do this if you
rather use a different linter.

Id Description Default

css.validate Enables or disables all css validations true

less.validate Enables or disables all less validations true

scss.validate Enables or disables all scss validations true

To configure an option for CSS, use css.lint. as the prefix to the id; for Sass and Less,
use scss.lint. and less.lint..
Set a setting to warning or error if you want to enable lint checking, use ignore to disable
it. Lint checks are performed as you type.
Id Description Default
validate Enables or disables all validations true
compatibleVendorPrefixes When using a property with a vendor-specific prefix ignore
(for example -webkit-transition), make sure to
also include all other vendor-specific properties eg. -
moz-transition, -ms-transition and
-o-transition
vendorPrefix When using a property with a vendor-specific prefix warning
for example -webkit-transition, make sure to also
include the standard property if it exists
eg. transition

R Manual – User Manual Pag. 53


Id Description Default
duplicateProperties Warn about duplicate properties in the same ruleset ignore
emptyRules Warn about empty rulesets warning
importStatement Warn about using an import statement as import ignore
statements are loaded sequentially which has a
negative impact on web page performance
boxModel Do not use width or height when using padding ignore
or border
universalSelector Warn when using the universal selector * as it is ignore
known to be slow and should be avoided
zeroUnits Warn when having zero with a unit e.g. 0em as zero ignore
does not need a unit.
fontFaceProperties Warn when using @font-face rule without defining warning
a src and font-family property
hexColorLength Warn when using hex numbers that don't consist of error
three or six hex numbers
argumentsInColorFunction Warn when an invalid number of parameters in color error
functions e.g. rgb
unknownProperties Warn when using an unknown property warning
ieHack Warn when using an IE hack *propertyName or ignore
_propertyName
unknownVendorSpecificProperties Warn when using an unknown vendor-specific ignore
property
propertyIgnoredDueToDisplay Warn when using a property that is ignored due to warning
the display. For example with display: inline,
the width, height, margin-top, margin-bottom,
and float properties have no effect.
important Warn when using !important as it is an indication ignore
that the specificity of the entire CSS has gotten out of
control and needs to be refactored.
float Warn when using float as floats lead to fragile CSS ignore
that is easy to break if one aspect of the layout
changes.
idSelector Warn when using selectors for an id #id as selectors ignore
should not contain IDs because these rules are too
tightly coupled with the HTML.

4.5.11. Next Steps


Read on to find out about:
 Configure Tasks - Dig into Tasks to help you transpile your Sass and Less to CSS.
 Basic Editing - Learn about the powerful VS Code editor.
 Code Navigation - Move quickly through your source code.
 HTML - CSS is just the start, HTML is also very well supported in VS Code.

Pag. 54 R Manual – User Manual


4.5.11. Common Questions
Q: Do you provide a color picker?
A: Yes, color picker has been added in version 1.15.
Q: Do you support the indentation based Sass syntax (.sass) ?
A: No, but there are several extensions in the Marketplace supporting the indented flavor of
Sass.
4.6. Editing TypeScript
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes,
modules, and interfaces to help you build robust components. The TypeScript language specification
can be found here.

4.6.1. Installing the TypeScript compiler


Visual Studio Code includes TypeScript language support but does not include the TypeScript
compiler, tsc. You will need to install the TypeScript compiler either globally or in your
workspace to transpile TypeScript source code to JavaScript (tsc HelloWorld.ts).
The easiest way to install TypeScript is through npm, the Node.js Package Manager. If you have npm
installed, you can install TypeScript globally (-g) on your computer by:
npm install -g typescript
You can test your install by checking the version or help.
tsc --version
tsc --help
Another option is to install the TypeScript compiler locally in your project (npm install --
save-dev typescript) and has the benefit of avoiding possible interactions with other TypeScript
projects you may have.
4.6.2. TypeScript files and projects
VS Code's TypeScript support can operate in two different modes:
 File Scope: In this mode, TypeScript files opened in Visual Studio Code are treated as
independent units. As long as a file a.ts doesn't reference a file b.ts explicitly (either
using /// reference directives or external modules), there is no common project
context between the two files.
 Explicit Project: A TypeScript project is defined via a tsconfig.json file. The presence
of such a file in a directory indicates that the directory is the root of a TypeScript
project. The file itself lists the files belonging to the project as well as compiler options.
Details about the tsconfig.json file can be found here.

R Manual – User Manual Pag. 55


Tip: We recommend that you use explicit projects over file scope projects. Since explicit
projects list the files belonging to a project language, features like Find All
References Shift+F12 consider the project scope and not the file scope only.
4.6.3. tsconfig.json
Typically the first step in any new TypeScript project is to add in a tsconfig.json file. This
defines the TypeScript project settings such as the compiler options and the files that should
be included. To do this, open up the folder where you want to store your source and add in a
new file named tsconfig.json. Once in this file, IntelliSense (Ctrl+Space) will help you
along the way.

A simple tsconfig.json looks like this for ES5, CommonJS modules and source maps:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}

Now when you create a .ts file as part of the project we will offer up rich editing experiences
and syntax validation.
4.6.3.1. typescript.reportStyleChecksAsWarnings
By default, VS Code TypeScript displays code style issues as warnings instead of errors. This
applies to:
 Variable is declared but never used
 Property is declared but its value is never read
 Unreachable code detected
 Unused label
 Fall through case in switch
 Not all code paths return a value
Treating these as warnings is consistent with other tools, such as TSLint. These will still be
displayed as errors when you run tsc from the command line.
You can disable this behavior by setting: "typescript.reportStyleChecksAsWarnings":
false in the User Settings file.

Pag. 56 R Manual – User Manual


4.6.4. Transpiling TypeScript into JavaScript
VS Code integrates with tsc through our integrated task runner. We can use this to transpile
.ts files into .js files. Another benefit of using VS Code tasks is that you get integrated error
and warning detection displayed in the Problems panel. Let's walk through transpiling a
simple TypeScript Hello World program.
a Tip: If you don't have the TypeScript compiler installed, you can get it here.

Step 1: Create a simple TS file


Open VS Code on an empty folder and create a HelloWorld.ts file, place the following code
in that file...

class Startup { public static main(): number { console.log('Hello World');


return 0; }
}
Startup.main();

To test that you have the TypeScript compiler tsc installed correctly and a working Hello
World program, open a terminal and type tsc HelloWorld.ts. You can use the Integrated
Terminal (Ctrl+`) directly in VS Code.

You should now see the transpiled HelloWorld.js JavaScript file which you can run if you
have Node.js installed, by typing node HelloWorld.js.
Step 2: Run the TypeScript build
Execute Run Build Task... from the global Tasks menu. If you created a tsconfig.json file
in the earlier section, this should present the following picker:

Select the tsc: build entry. This will produce a HelloWorld.js and HelloWorld.js.map file
in the workspace.
If you selected tsc: watch, the TypeScript compiler watches for changes to your TypeScript
files and runs the transpiler on each change.
Under the covers, we run the TypeScript compiler as a task. The command we use is: tsc -p .
Step 3: Make the TypeScript Build the default
You can also define the TypeScript build task as the default build task so that it is executed
directly when triggering Run Build Task (Ctrl+Shift+B). To do so select Configure Default
Build Task from the global Tasks menu. This shows you a picker with the available build
tasks.

R Manual – User Manual Pag. 57


Select TypeScript tsc: build which generates the following tasks.json file:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{ "type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [ "$tsc" ],
"group": { "kind": "build",
"isDefault": true } } ] }

The example TypeScript file did not have any compile problems, so by running the task all
that happened was a corresponding HelloWorld.js and HelloWorld.js.map file was
created.
Tip: You can also run the program using VS Code's Run/Debug feature. Details about
running and debugging Node.js applications in VS Code can be found here.
Step 4: Reviewing build issues
Unfortunately, most builds don't go that smoothly and the result is often some additional
information. For instance, if there was a simple error in our TypeScript file, we may get the
following output from tsc:
HelloWorld.ts(3,17): error TS2339: Property 'logg' does not exist on type 'Console'.

This would show up in the terminal panel (Ctrl+`) and selecting the terminal Tasks - build
tsconfig.json in the terminal view drop-down. VS Code uses a problem matcher, in this case
one specific to the TypeScript compiler, to parse this output and highlight detected
problems. You can see this in the generated tasks.json above, where the problemMatcher
attribute is set to $tsc.
You can see the error and warning counts in the Status Bar:

Click on the error and warnings icon to get a list of the problems and navigate to them.

You can also use the keyboard to open the list Ctrl+Shift+M.
Tip: Tasks offer rich support for many actions. Check the Tasks topic for more information
on how to configure them.

Pag. 58 R Manual – User Manual


4.6.5. Goto Symbol & Show All Symbols
Ctrl+Shift+O: lists all defined symbols of the current open TypeScript and lets you navigate in it.
Ctrl+T: lets you search all symbols defined in the current project or file scope. You need to
have a TypeScript file open in the active editor.
4.6.6. Format Code
Shift+Alt+F: formats the whole document. Ctrl+K Ctrl+F: formats the currently selected
source code.
4.6.7. JSDoc support
VS Code offers JSDoc support for TypeScript. Besides syntax coloring, we help you enter
JSDoc comments. Type /** and it will auto insert the closing */. Pressing Enter inside
a JSDoc block will indent the next line and auto insert a *.
4.6.8. JavaScript source map support
TypeScript debugging supports JavaScript source maps. Enable this by setting the
sourceMaps attribute to true in the project's launch configuration file launch.json. In
addition, you can specify a TypeScript file with the program attribute.
To generate source maps for your TypeScript files, compile with the --sourcemap option or
set the sourceMap property in the tsconfig.json file to true.
In-lined source maps (a source map where the content is stored as a data URL instead of a
separate file) are also supported, although in-lined source is not yet supported.
4.6.9. Setting a different outFiles for generated files
If generated (transpiled) JavaScript files do not live next to their source, you can help the VS
Code debugger locate them by setting the outFiles attribute in the launch configuration.
Whenever you set a breakpoint in the original source, VS Code tries to find the generated
source by searching the files specified by glob patterns in outFiles.
4.6.10. Hiding derived JavaScript files
When you are working with TypeScript, you often don’t want to see generated JavaScript files
in the explorer or in search results. VS Code offers filtering capabilities with a files.exclude
workspace setting (File > Preferences > Settings) and you can easily create an expression
to hide those derived files:
"**/*.js": { "when": "$(basename).ts"}
This pattern will match on any JavaScript file (**/*.js) but only if a sibling TypeScript file
with the same name is present. The file explorer will no longer show derived resources for
JavaScript if they are compiled to the same location.

R Manual – User Manual Pag. 59


To exclude JavaScript files generated from both .ts and .tsx source files, use this
expression:

"**/*.js": { "when": "$(basename).ts" },


"**/**.js": { "when": "$(basename).tsx" }

This is a bit of a trick. The search glob pattern is used as a key. The settings above use two
different glob patterns to provide two unique keys but the search will still match the same
files.
4.6.11. Mixed TypeScript and JavaScript projects
It is now possible to have mixed TypeScript and JavaScript projects. To enable JavaScript
inside a TypeScript project, you can set the allowJs property to true in the tsconfig.json.
Tip: The tsc compiler does not detect the presence of a jsconfig.json file automatically.
Use the –p argument to make tsc use your jsconfig.json file, e.g. tsc -p jsconfig.json.

4.6.12. Using newer TypeScript versions


VS Code ships with a recent stable version of the TypeScript language service and the active
version of the TypeScript language service is displayed in the Status Bar when viewing a
TypeScript or JavaScript file:

Tip: To get a specific TypeScript version, specify @version during npm install. For example
for TypeScript 2.2.1, you would use npm install --save-dev typescript@2.2.1. To
preview the next version of TypeScript, run npm install --save-dev typescript@next.
To use a different TypeScript version by default, configure typescript.tsdk in your user
settings to point to a directory containing the TypeScript tsserver.js file. You can find the
TypeScript installation location using npm list -g typescript. The tsserver.js file is
usually in the lib folder.
For example:

{
"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib"
}

You can also configure a specific version of TypeScript in a particular workspace by adding
a typescript.tsdk workspace setting pointing to the directory of the tsserver.js file:

{
"typescript.tsdk": "./node_modules/typescript/lib"
}

Note that while typescript.tsdk points to the lib directory inside of typescript in these
examples, the typescript directory must be a full TypeScript install that contains the
TypeScript package.json file.

Pag. 60 R Manual – User Manual


4.6.12.1. Using the workspace version of TypeScript
If your workspace has a specific TypeScript version, you can switch between the workspace
version of TypeScript and the version that VS Code uses by default by opening a TypeScript
or JavaScript file in the workspace and clicking on the TypeScript version number in the
Status Bar. A message box will appear asking you which version of TypeScript VS Code
should use:

You can switch back to the version of TypeScript that comes with VS Code by clicking on the
TypeScript version in the Status Bar again.
4.6.13. Auto imports
Automatic imports speed up coding by helping you find available symbols and automatically
adding imports for them.
Just start typing to see suggestions for all available TypeScript symbols in your current
project.

R Manual – User Manual Pag. 61


If you choose one of the suggestion from another file or module, VS Code will automatically
add an import for it. In this example, VS Code adds an import for Hercules to the top of the
file:

Auto imports requires TypeScript 2.6+ and are enabled by default. You can disable auto
imports by setting "typescript.autoImportSuggestions.enabled": false.
4.6.14. References CodeLens
The TypeScript references CodeLens displays an inline count of reference for classes,
interfaces, methods, properties, and exported objects:

You can enable this by setting "typescript.referencesCodeLens.enabled": true in the


User Settings file.

Pag. 62 R Manual – User Manual


Click on the reference count to quickly browse a list of references:

4.6.15. Implementations CodeLens


The TypeScript implementations CodeLens displays the number of implementors of an interface:

You can enable this by setting "typescript.implementationsCodeLens.enabled": true.


As with the references CodeLens, you can click on the implementation count to quickly
browse a list of all implementations.

R Manual – User Manual Pag. 63


4.6.16. TypeScript extensions
VS Code provides many features for TypeScript out of the box. In addition to what comes
built-in, you can install an extension for greater functionality.

TSLint Angular v5 Snippets Document This TypeScript Toolbox


eg2 4636.8K johnpapa 2779.6K joelday 608.3K DSKWRK 133.8K
TSLint for Visual Studio Angular v5 snippets by John Automatically generates Add and Optimize Imports,
Code Papa detailed JSDoc comments i... Generate Getters / Sett...

Tip: Click on an extension tile above to read the description and reviews to decide which
extension is best for you. See more in the Marketplace.
4.6.17. Next Steps
OK, read on to find out about:
 JavaScript - we have several JavaScript specific features in VS Code
 Tasks - we used tasks to transpile your TS file. Read more to find out what else tasks can do
 Basic Editing - Learn about the powerful VS Code editor.
 Code Navigation - Move quickly through your source code.
 Debugging - we support debugging TypeScript Node.js apps
4.6.18. Common Questions
Q: How do I resolve a TypeScript "Cannot compile external module" error?
A: If you get that error, resolve it by creating a tsconfig.json file in the root folder of your
project. The tsconfig.json file lets you control how Visual Studio Code compiles your
TypeScript code. For more information, see the tsconfig.json overview.
Due to a current limitation, you must restart VS Code after adding the tsconfig.json file.
Q: Why do I get different errors and warnings with VS Code than when I compile my
TypeScript project?
VS Code ships with a recent stable version of the TypeScript language service and it may not
match the version of TypeScript installed globally on your computer or locally in your
workspace. For that reason, you may see differences between your compiler output and
errors detected by the active TypeScript language service. See Using newer TypeScript
versions for details on installing a matching TypeScript version.
Q: Can I use the version of TypeScript that ships with VS 2015?
A: No, the TypeScript language service which ships with Visual Studio 2015 and 2017 isn't
compatible with VS Code. You will need to install a separate version of TypeScript from npm.

Pag. 64 R Manual – User Manual


4.7. Markdown and VS Code
Working with Markdown files in Visual Studio Code is simple, straightforward, and fun.
Besides VS Code's basic editing, there are a number of Markdown specific features that will
help you be more productive.
4.7.1. Markdown extensions
In addition to the functionality VS Code provides out of the box, you can install an extension
for greater functionality.

markdownlint Markdown Theme Kit Markdown TOC Markdown Shortcuts


DavidAnson 1107.4K ms-vscode 161.4K AlanWalk 55.1K mdickin 38.7K
Markdown linting and style Theme Kit for VS Code Markdown TOC(Table Of Shortcuts for Markdown
checking for Visual St... optimized for Markdown... Contents) Plugin for Visual... editing

Tip: Click on an extension tile above to read the description and reviews to decide which
extension is best for you. See more in the Marketplace.
4.7.2. Markdown preview
VS Code supports Markdown files out of the box. You just start writing Markdown text, save
the file with the .md extension and then you can toggle the visualization of the editor
between the code and the preview of the Markdown file; obviously, you can also open an
existing Markdown file and start working with it. To switch between views, press
Ctrl+Shift+V in the editor. You can view the preview side-by-side (Ctrl+K V) with the file
you are editing and see changes reflected in real-time as you edit.
Here is an example with a very simple file.

R Manual – User Manual Pag. 65


Tip: You can also right-click on the editor Tab and select Open Preview to the Side or use
the Command Palette (Ctrl+Shift+P) to run the Markdown: Open Preview to the
Side command.
4.7.2.1. Dynamic previews and preview locking
By default, Markdown previews automatically update to preview the currently active
Markdown file:

You can lock a Markdown preview using the Markdown: Toggle Preview Locking command
to keep it locked to its current Markdown document. Locked previews are indicated
by [Preview] in the title:

4.7.2.2. Editor and preview synchronization


VS Code automatically synchronizes the Markdown editor and the preview views. Scroll the
Markdown preview and the editor is scrolled to match the preview's viewport. Scroll the
Markdown editor and the preview is scrolled to match its viewport:

Pag. 66 R Manual – User Manual


You can disable scroll synchronization using the markdown.preview.scrollPreviewWith
Editor and markdown.preview.scrollEditorWithPreview settings.
The currently selected line in the editor is indicated in the Markdown preview by a light gray
bar in the left margin:

Additionally, double clicking an element in the Markdown preview will automatically open the
editor for the file and scroll to the line nearest the clicked element.

4.7.2.3. Extending the Markdown preview


Extensions can contribute custom styles and scripts to the Markdown preview to change its
appearance and add new functionality. Here's a set of example extensions that customize the
preview:

Markdown+Math Markdown Preview Git... Markdown Emoji Markdown Preview wit...


goessner 98.4K bierner 42.6K bierner 35.1K hbrok 346
Changes VS Code's built-in Adds emoji syntax support Replaces the Markdown
LaTeX Math for Markdown
markdown preview to ma... to VS Code's built-in m... preview with Bitbucket styl...

R Manual – User Manual Pag. 67


4.7.2.4. Using your own CSS
You can also use your own CSS in the Markdown preview with the "markdown.styles":
[] setting. This lists URLs for style sheets to load in the Markdown preview. These stylesheets
can either be https urls, or relative paths to local files in the current workspace.
For example, to load a stylesheet called Style.css at the root of your current workspace,
use File > Preferences > Settings to bring up the workspace settings.json file and make
this update:

// Place your settings in this file to overwrite default and user settings.
{
"markdown.styles": [
"Style.css"
]
}

4.7.3. Markdown preview security


For security reasons, VS Code restricts the content displayed in the Markdown preview. This
includes disabling script execution and only allowing resources to be loaded over https.
When the Markdown preview blocks content on a page, an alert popup is shown in the top
right corner of the preview window:

You can change what content is allowed in the Markdown preview by clicking on this popup
or running the Markdown: Change preview security settings command in any Markdown
file:

The Markdown preview security settings apply to all files in the workspace.
Here are the details about each of these security levels:
4.7.3.1. Strict
This is the default setting. Only loads trusted content and disables script execution. Blocks
http images and all SVG images not from one of our trusted badge providers.

Pag. 68 R Manual – User Manual


It is strongly recommended that you keep Strict security enabled unless you have a very
good reason to change it AND you trust all markdown files in the workspace.
4.7.3.2. Allow insecure content
Keeps scripts disabled but allows content to be loaded over http. Also enables SVG images.
4.7.3.3. Disable
Disables additional security in the preview window. This allows script execution and also
allows content to be loaded over http.

4.7.4. Snippets for Markdown


There are several built-in Markdown snippets included in VS Code - press Ctrl+Space
(Trigger Suggest) and you get a context specific list of suggestions.
Tip: You can add in your own User Defined Snippets for Markdown. Take a look at User
Defined Snippets to find out how.

4.7.5. Compiling Markdown into HTML


VS Code integrates with Markdown compilers through the integrated task runner. We can
use this to compile .md files into .html files. Let's walk through compiling a simple
Markdown document.
Step 1: Install a Markdown compiler
For this walkthrough, we use the popular Node.js module, markdown-it.

npm install -g markdown-it

Note: There are many Markdown compilers to choose from beyond markdown-it. Pick
the one that best suits your needs and environment.
Step 2: Create a simple MD file
Open VS Code on an empty folder and create a sample.md file.
Note: You can open a folder with VS Code by either selecting the folder with File > Open
Folder...or navigating to the folder and typing 'code .' at the command line.
Place the following source code in that file:

# Hello Markdown in VS Code!

This is a simple introduction to compiling Markdown in VS Code.

Things you'll need:

* [node](https://nodejs.org)
* [markdown-it](https://www.npmjs.com/package/markdown-it)
* [tasks.json](/docs/editor/tasks)

## Section Title

> This block quote is here for your information.

R Manual – User Manual Pag. 69


Step 3: Create tasks.json
The next step is to set up the task configuration file tasks.json. To do this, run Tasks >
Configure Tasks and click Create tasks.json file from templates. VS Code then presents a
list of possible tasks.json templates to choose from. Select Others since we want to run an
external command.
This generates a tasks.json file in your workspace .vscode folder with the following
content:

{ // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [ { "label": "echo",
"type": "shell",
"command": "echo Hello" } ]
}

To use markdown-it to compile the Markdown file, change the contents as follows:

{ // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [ { "label": "Compile Markdown",
"type": "shell",
"command": "markdown-it sample.md -o sample.html",
"group": "build" } ]
}

Tip: While the sample is there to help with common configuration settings, IntelliSense is
available for the tasks.json file as well to help you along. Use Ctrl+Space to see the
available settings.
Step 4: Run the Build Task
Since in more complex environments there can be more than one build task we prompt you
to pick the task to execute after pressing Ctrl+Shift+B (Run Build Task). In addition we
allow you to scan the output for compile problems. Since we only want to convert the
Markdown file to HTML select Never scan the build output from the presented list.
At this point, you should see an additional file show up in the file list sample.html.
If you want to make the Compile Markdown task the default build task to run execute
Configure Default Build Task from the global Tasks menu and select Compile Markdown
from the presented list. The final tasks.json file will then look like this:

{ // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [ { "label": "Compile Markdown",
"type": "shell",
"command": "markdown-it sample.md -o sample.html",
"problemMatcher": [],
"group": { "kind": "build",
"isDefault": true } } ]
}

Pag. 70 R Manual – User Manual


4.7.6. Automating Markdown compilation
Let's take things a little further and automate Markdown compilation with VS Code. We can
do so with the same task runner integration as before, but with a few modifications.
Step 1: Install Gulp and some plug-ins
We use Gulp to create a task that automates Markdown compilation. We also use the gulp-
markdown plug-in to make things a little easier.
We need to install gulp both globally (-g switch) and locally:

npm install -g gulp


npm install gulp gulp-markdown-it

Note: gulp-markdown-it is a Gulp plug-in for the markdown-it module we were using
before. There are many other Gulp Markdown plug-ins you can use, as well as plug-ins for
Grunt.
You can test that your gulp installation was successful but typing gulp -v. You should see a
version displayed for both the global (CLI) and local installations.
Step 2: Create a simple Gulp task
Open VS Code on the same folder from before (contains sample.md and tasks.json under
the .vscode folder), and create gulpfile.js at the root.
Place the following source code in that file:

var gulp = require('gulp');


var markdown = require('gulp-markdown-it');
gulp.task('markdown', function() {
return gulp.src('**/*.md')
.pipe(markdown())
.pipe(gulp.dest(function(f) { return f.base; }));
});
gulp.task('default', ['markdown'], function() {
gulp.watch('**/*.md', ['markdown']);
});

What is happening here?


1. We are watching for changes to any Markdown file in our workspace, i.e. the current
folder open in VS Code.
2. We take the set of Markdown files that have changed, and run them through our
Markdown compiler, i.e. gulp-markdown-it.
3. We now have a set of HTML files, each named respectively after their original Markdown
file. We then put these files in the same directory.
Step 3: Run the gulp default Task
To complete the tasks integration with VS Code, we will need to modify the task
configuration from before to run the default Gulp task we just created. You can either delete
the tasks.json file or empty it only keeping the "version": "2.0.0" property. Now
execute Run Task from the global Tasks menu. Observe that you are presented with a picker
listing the tasks defined in the gulp file. Select gulp: default to start the task. We allow you
to scan the output for compile problems.
R Manual – User Manual Pag. 71
Since we only want to convert the Markdown file to HTML select Never scan the build
output from the presented list. At this point, if you create and/or modify other Markdown
files, you see the respective HTML files generated and/or changes reflected on save. You can
also enable Auto Save to make things even more streamlined.
If you want to make the gulp: default task the default build task executed when pressing
Ctrl+Shift+B run Configure Default Build Task from the global Tasks menu and select
gulp: default from the presented list. The final tasks.json file will then look like this:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "gulp",
"task": "default",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

Step 4: Terminate the gulp default Task


The gulp: default task runs in the background and watches for file changes to Markdown
files. If you want to stop the task, you can use the Terminate Running Task from the
global Tasks menu.

4.7.7. Next Steps


Read on to find out about:
 CSS, Less and Sass - Want to edit your CSS? VS Code has great support for CSS, Less
and Sass editing.

4.7.8. Common Questions


Q: Is there spell checking?
A: Not installed with VS Code but there are spell checking extensions. Check the VS Code
Marketplace to look for useful extensions to help with your workflow.
Q: Does VS Code support GitHub Flavored Markdown?
A: No, VS Code targets the CommonMark Markdown specification using the markdown-
it library. GitHub is moving toward the CommonMark specification which you can read about
in this update.
Q: In the walkthrough above, I didn't find the Configure Task Runner command in the
Command Palette?
A: You may have opened a file in VS Code rather than a folder. You can open a folder by
either selecting the folder with File > Open Folder... or navigating to the folder and typing
'code .' at the command line.

Pag. 72 R Manual – User Manual


4.8. C/C++ for VS Code (Preview)
C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to
enable cross-platform C and C++ development using VS Code on Windows, Linux, and
macOS. The extension is still in preview and our focus is code editing, navigation, and
debugging support for C and C++ code everywhere that VS Code runs.

If you just want a lightweight tool to edit your C++ files, Visual Studio Code is a great choice
but if you want the best possible experience for your existing Visual C++ projects or
debugging on Windows, we recommend you use a version of Visual Studio such as Visual
Studio Community.
If you run into any issues or have suggestions for the Microsoft C/C++ extension, please
file issues and suggestions on GitHub. If you haven't already provided feedback, please
take this quick survey to help shape this extension for your needs.
Note for Linux users: The C/C++ extension works on 64-bit Linux distros that have glibc
2.18 or later installed.

4.8.1. Getting Started


To install the Microsoft C/C++ extension:
 Open VS Code.
 Click the Extensions View icon on the Sidebar.
 Search for c++.
 Click Install, then click Reload.

With the C/C++ extension installed, open a folder that contains your C/C++ source code. VS
Code will place various settings files into a .vscode subfolder.
Note: The C/C++ extension does not include a C++ compiler or debugger. You will need to
install these tools or use those already installed on your computer. Popular C++ compilers
are MinGW for Windows, XCode for macOS, and GCC on Linux. Also make sure your
compiler executable is on your platform path for VS Code to find.

R Manual – User Manual Pag. 73


4.8.1.1. IntelliSense
To enable code completion and navigation, you will need to generate a
c_cpp_properties.json file:
 Find any green squiggle in a source file (for example, an #include statement) and set the
cursor on the line.
 Click the lightbulb that appears in the left gutter.
 Click Update "browse.path" setting.

This will generate a c_cpp_properties.json file that allows you to add additional browse
paths to properly enable code navigation and auto-completion. The generated
c_cpp_properties.json file has sections for different operating systems, make sure you
update the appropriate settings for your current platform.
Below you can see that the MinGW C++ include path has been added to browse.path for
Windows:

{
"name": "Win32",
"includePath": [
"${workspaceFolder}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceFolder}",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}

Note: You can also generate or edit a c_cpp_properties.json file with the C/Cpp: Edit
Configurations command from the Command Palette (Ctrl+Shift+P).

Pag. 74 R Manual – User Manual


4.8.1.2. Building your code
If you want to build your application from VS Code, you will need to generate a
tasks.json file:
 Open the Command Palette (Ctrl+Shift+P).
 Select the Tasks: Configure Tasks... command, click Create tasks.json file from
templates, and you will see a list of task runner templates.
 Select Others to create a task which runs an external command.
 Change the command to the command line expression you use to build your application
(for example g++).
 Add any required args (for example -g to build for debugging).
 You can also change the label to be more descriptive.
You should now see a tasks.json file in your workspace .vscode folder that looks something like:

{
"version": "2.0.0",
"tasks": [ { "label": "build hello world",
"type": "shell",
"command": "g++",
"args": [ "-g", "helloworld.cpp" ] } ]
}

If you'd like to be able to build your application with Tasks: Run Build Task (Ctrl+Shift+B),
you can add it to the build group.
{
"version": "2.0.0",
"tasks": [ { "label": "build hello world",
"type": "shell",
"command": "g++",
"args": [ "-g", "helloworld.cpp" ],
"group": { "kind": "build",
"isDefault": true } } ]
}

For more information on tasks, see Integrate with External Tools via Tasks.
4.8.1.3. Debugging your code
To enable debugging, you will need to generate a launch.json file:
 Navigate to the Debug view by clicking the Debug icon in the Sidebar.
 In the Debug view, click the Configure icon.
 Select C++ (GDB/LLDB) (to use GDB or LLDB) or C++ (Windows) (to use the Visual
Studio Windows Debugger) from the Select Environment dropdown. This creates a
launch.json file for editing with two configurations:
o C++ Launch defines the properties for launching your application when you start
debugging.
o C++ Attach defines the properties for attaching to a process that's already running.
 Update the program property with the path to the program you are debugging.
 If you want your application to build when you start debugging, add a preLaunchTask
property with the name of the build task you created in tasks.json ("build hello
world" in the example above).

R Manual – User Manual Pag. 75


Below is an example using the MinGW GDB debugger:

{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build hello world"
}
]
}

To learn more, see Configuring launch.json for C/C++ debugging.


If you are debugging with GDB on Windows, see Windows Debugging with GDB.
4.8.2. Editing Code
4.8.2.1. Code Formatting
The C/C++ extension for Visual Studio Code supports source code formatting using clang-
format which is included with the extension.
You can format an entire file with Format Document (Shift+Alt+F) or just the current
selection with Format Selection (Ctrl+K Ctrl+F) in right-click context menu. You can also
configure auto-formatting with the following settings:
 C_Cpp.clang_format_formatOnSave - to format when you save your file.
 editor.formatOnType - to format as you type (triggered on the ; character).
By default, the clang-format style is set to "file" which means it looks for a .clang-
format file inside your workspace. If the .clang-format file is found, formatting is applied
according to the settings specified in the file. If no .clang-format file is found in your
workspace, formatting is applied based on a default style specified in the
C_Cpp.clang_format_fallbackStyle setting instead. Currently, the default formatting
style is "Visual Studio". Using "Visual Studio" formatting ensures that source code formatting
will be compatible in both VS Code and Visual Studio Community.

Pag. 76 R Manual – User Manual


The "Visual Studio" clang-format style is not yet an official OOTB clang-format style but it
implies the following clang-format settings:

UseTab: (VS Code current setting)


IndentWidth: (VS Code current setting)
BreakBeforeBraces: AllMan
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0

If you'd like to use a different version of clang-format than the one that ships with the
extension, you can use the C_Cpp.clang_format_path setting and set its value to the path
where the clang-format binary is installed.
For example on the Windows platform:
"C_Cpp.clang_format_path": "C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe"

4.8.2.2. Fuzzy Auto-Complete


Fuzzy auto-complete is powered by an enhanced tag-parser approach. Although suggestions
are not based on semantic analysis of your code, this feature provides a wider selection of
matches than the single-file IntelliSense experience provided today.
In particular, this feature's capabilities give a good experience for C code.
4.8.3. Navigating Code
The source code navigation features provided by the C/C++ extension are powerful tools for
understanding and getting around in your codebase. These features are powered by tags
stored in an offline database of symbol information. With the C/C++ extension installed, this
database is generated whenever a folder containing C++ source code files is loaded into VS
Code. The platform indicator (Win32 in the figure below) turns red and appears next to a
flame icon while the tag-parser is generating this information.

When the platform indicator returns to its normal appearance, the source code symbols have
been tagged in the offline database and source code navigation features are ready to be
used.
4.8.3.1. Specifying Additional Include Directories for Better Symbol Support
To provide the best experience, the C/C++ extension for VS Code needs to know where it can
find each header file referenced in your code. By default, the extension searches the current
source directory, its sub-directories, and some platform-specific locations. If a referenced
header file can't be found, VS Code displays a green squiggle underneath each #include
directive that references it.
To specify additional include directories to be searched, place your cursor over any #include
directive that displays a green squiggle, then click the lightbulb action when it appears. This
opens the file c_cpp_properties.json for editing; here you can specify additional include
directories for each platform configuration individually by adding more directories to the
'browse.path' property.

R Manual – User Manual Pag. 77


4.8.3.2. Search for Symbols
You can search for symbols in the current file or workspace to navigate your code more
quickly.
To search for a symbol in the current file, press Ctrl+Shift+O, then enter the name of the
symbol you're looking for. A list of potential matches will appear and be filtered as you type.
Choose from the list of matches to navigate to its location.

To search for a symbol in the current workspace, start by pressing Ctrl+T instead, then enter
the name of the symbol. A list of potential matches will appear as before. If you choose a
match that was found in a file that's not already open, the file will be opened before
navigating to the match's location.

Pag. 78 R Manual – User Manual


Alternatively, you can search for symbols by accessing these commands through the
Command Palette if you prefer. Use Quick Open (Ctrl+P) then enter the '@' command to
search the current file, or the '#' command to search the current workspace. Ctrl+Shift+O
and Ctrl+T are just shortcuts for the '@' and '#' commands, respectively, so everything
works the same.
4.8.3.4. Peek Definition
You can take a quick look at how a symbol was defined by using the Peek Definition feature.
This feature displays a few lines of code near the definition inside a peek window so you can
take a look without navigating away from your current location.
To peek at a symbol's definition, place your cursor on the symbol anywhere it's used in your
source code and then press Alt+F12. Alternatively, you can choose Peek Definition from the
context menu (right-click, then choose Peek Definition).

R Manual – User Manual Pag. 79


Currently, the C/C++ extension doesn't parse code in a way that helps it distinguish between
competing definitions based on how the symbol is used. These competing definitions arise
when the symbol defines different things in different contexts, such as occurs with over-
loaded functions, classes and their constructors, and other situations. When this happens,
each of the competing definitions are listed in the right-hand side of the peek window with
the source code of the current selection displayed on the left.
With the peek window open, you browse the list of competing definitions to find the one
you're interested in. If you want to navigate to the location of one of the definitions just
double-click the definition you're interested in, or by double-clicking anywhere in the source
code displayed on the left-hand side of the peek window.
4.8.3.5. Go to Definition
You can also quickly navigate to where a symbol is defined by using the Go to Definition feature.
To go to a symbol's definition, place your cursor on the symbol anywhere it is used in your
source code and then press F12. Alternatively, you can choose Go to Definition from the
context menu (right-click, then choose Go to Definition). When there's only one definition of
the symbol, you'll navigate directly to its location, otherwise the competing definitions are
displayed in a peek window as described in the previous section and you have to choose the
definition that you want to go to.

Pag. 80 R Manual – User Manual


4.8.4. Debugging
After you have set up the basics of your debugging environment as specified in Getting
Started, you can learn more details about debugging C/C++ in this section.
VS Code supports the following debuggers for C/C++ depending on the operating system
you are using:
 Linux: GDB
 macOS: LLDB or GDB
 Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)
4.8.4.1. Windows Debugging with GDB
You can debug Windows applications created using Cygwin or MinGW by using VS Code. To
use Cygwin or MinGW debugging features, the debugger path must be set manually in the
launch configuration (launch.json). To debug your Cygwin or MinGW application, add the
miDebuggerPath property and set its value to the location of the corresponding gdb.exe for
your Cygwin or MinGW environment.
For example:
"miDebuggerPath": "c:\\mingw\\bin\\gdb.exe"
Cygwin/MinGW debugging on Windows supports both attach and launch debugging scenarios.
4.8.4.2. Conditional Breakpoints
Conditional breakpoints enable you to break execution on a particular line of code only when the
value of the condition is true. To set a conditional breakpoint, right-click on an existing
breakpoint and select Edit Breakpoint. This opens a small peek window where you can enter the
condition that must evaluate to true in order for the breakpoint to be hit during debugging.

In the editor, conditional breakpoints are indicated by a breakpoint symbol that has a black
equals sign inside of it. You can place the cursor over a conditional breakpoint to show its
condition.
4.8.4.3. Function Breakpoints
Function breakpoints enable you to break execution at the beginning of a function instead of
on a particular line of code. To set a function breakpoint, on the Debug pane right-click
inside the Breakpoints section, then choose Add Function Breakpoint and enter the name
of the function on which you want to break execution.
4.8.4.4. Expression Evaluation
VS Code supports expression evaluation in several contexts:
 You can type an expression into the Watch section of the Debug panel and it will be
evaluated each time a breakpoint is hit.
 You can type an expression into the Debug Console and it will be evaluated only once.
 You can evaluate any expression that appears in your code while you're stopped at a
breakpoint.

R Manual – User Manual Pag. 81


Note that expressions in the Watch section take effect in the application being debugged; an
expression that modifies the value of a variable will modify that variable for the duration of
the program.
4.8.4.5. Multi-threaded Debugging
The C/C++ extension for VS Code has the ability to debug multi-threaded programs. All
threads and their call stacks appear in the Call Stack section:

4.8.4.6. Memory Dump Debugging


The C/C++ extension for VS Code also has the ability to debug memory dumps. To debug a
memory dump, open your launch.json file and add the coreDumpPath (for GDB or LLDB)
or dumpPath (for the Visual Studio Windows Debugger) property to the C++ Launch
configuration, set its value to be a string containing the path to the memory dump. This will
even work for x86 programs being debugged on an x64 machine.
4.8.4.7. Additional Symbols
If there are additional directories where the debugger can find symbol files (for example,
.pdb files for the Visual Studio Windows Debugger), they can be specified by adding
the additionalSOLibSearchPath (for GDB or LLDB) or symbolSearchPath (for the Visual
Studio Windows Debugger).
For example:

"additionalSOLibSearchPath": "/path/to/symbols;/another/path/to/symbols"

or

"symbolSearchPath": "C:\\path\\to\\symbols;C:\\another\\path\\to\\symbols"

4.8.4.8. Locate source files


The source file location can be changed if the source files are not located in the compilation
location. This is done by simple replacement pairs added in the sourceFileMap section. The
first match in this list will be used.

Pag. 82 R Manual – User Manual


For example:

"sourceFileMap": {
"/build/gcc-4.8-fNUjSI/gcc-4.8-4.8.4/build/i686-linux-gnu/libstdc++-v3/
include/i686-linux-gnu": "/usr/include/i686-linux-gnu/c++/4.8",
"/build/gcc-4.8-fNUjSI/gcc-4.8-4.8.4/build/i686-linux-gnu/libstdc++-v3/
include": "/usr/include/c++/4.8" }

4.8.4.9. GDB, LLDB and MI Commands (GDB/LLDB)


For the C++ (GDB/LLDB) debugging environment, you can execute GDB, LLDB and MI commands
directly through the debug console with the -exec command, but be careful, executing commands
directly in the debug console is untested and might crash VS Code in some cases.
4.8.4.10. Other Debugging Features
 Unconditional breakpoints
 Watch window
 Call stack
 Stepping
For more information on debugging with VS Code, see this introduction to debugging in VS Code.
4.8.5. Known Limitations
4.8.5.1. Symbols and Code Navigation
All platforms:
 Because the extension doesn't parse function bodies, Peek Definition and Go to
Definition don't work for symbols defined inside the body of a function.
4.8.5.2. Debugging
Windows:
 GDB on Cygwin and MinGW cannot break a running process. To set a breakpoint when
the application is running (not stopped under the debugger), or to pause the
application being debugged, press Ctrl-C in the application's terminal.
 GDB on Cygwin cannot open core dumps.
Linux:
 GDB needs elevated permissions to attach to a process. When using attach to process,
you need to provide your password before the debugging session can begin.
macOS:
 LLDB:
o When debugging with LLDB, if the Terminal window is closed while in break mode,
debugging does not stop. Debugging can be stopped by pressing the Stop button.
o When debugging is stopped the Terminal window is not closed.
 GDB:
o Additional manual install steps need to be completed to use GDB on macOS. See
Manual Installation of GDB for OS X in the README.
o When attaching to a process with GDB, the application being debugged cannot be
interrupted. GDB will only bind breakpoints set while the application is not running
(either before attaching to the application, or while the application is in a stopped
state). This is due to a bug in GDB.
o Core dumps cannot be loaded when debugging with GDB because GDB does not
support the core dump format used in macOS.
o When attached to a process with GDB, break-all will end the process.

R Manual – User Manual Pag. 83


4.8.6. Next Steps
Read on to find out about:
 Basic Editing - Learn about the powerful VS Code editor.
 Code Navigation - Move quickly through your source code.
 Tasks - use tasks to build your project and more
 Debugging - find out how to use the debugger with your project
4.8.7. Common Questions
Q: My project won't load.
A: VS Code doesn't currently support C++ project files, instead it considers a directory of
your choosing to be the workspace of your project. Source code files inside that directory
and its sub-directories are part of the workspace.
Q: How do I build/run my project?
A: VS Code supports tasks that you can configure to build your application, and natively
understands the output of MSBuild, CSC, and XBuild. For more information, see the Tasks
documentation.
If you have any other questions or run into any issues, please file an issue on GitHub.

4.9. Java in VS Code


The Java support in VS Code is provided through extensions and optimized for lightweight
Java projects with a simple, modern workflow. Popular extensions in the Marketplace
provide essential language features such as project support, code completion, linting,
debugging, testing, code formatting, snippets, as well as tooling integration including Maven
and Tomcat.
Download VS Code - If you haven't downloaded VS Code yet, quickly install for your
platform (Windows, Mac, Linux).
4.9.1. Install Java Extensions
VS Code is a fast editor and ships with great editing features. Add Java language support to
VS Code by installing the popular Java extensions. To help set up Java on VS Code, there is
a Java Extension Pack which contains popular extensions we picked for most Java
developers:
1. Language Support for Java(TM) by Red Hat
2. Debugger for Java
3. Java Test Runner
4. Maven for Java
There're also other popular Java extensions you can pick for your own needs, including:
1. Spring Boot Support
2. Spring Initializer Java Support
3. Tomcat
4. CheckStyle

Pag. 84 R Manual – User Manual


Thanks to the great Java community around VS Code, the list doesn't end there. You can
search for more Java extensions easily within VS Code:
1. Go to the Extensions view (Ctrl+Shift+X).
2. Filter the extensions list by typing "java".
This document describes some of the key features included in those Java extensions.
4.9.2. Java Project Support
Maven, Eclipse and Gradle Java project are supported through Language Support for
Java(TM) by Red Hat, by utilizing M2Eclipse which provides Maven support and Buildship
which provides Gradle support through the Eclipse JDT Language Server.
With Maven for Java, you can generate projects from Maven Archetype, browse through all
the Maven projects within your workspace, and execute Maven goals easily from an
embedded explorer.

R Manual – User Manual Pag. 85


4.9.3. Editing and Navigating Code

4.9.3.1. Linting
A linter is a tool that provides warnings for suspicious looking code. Language Support for
Java(TM) by Red Hat provides this feature to report parsing and compilation errors as you
type, so you can fix them inside VS Code.
4.9.3.2. Intellisense
VS Code also supports code completion and Intellisense for Java through Language Support
for Java(TM) by Red Hat. Intellisense is a general term for a number of features, including
intelligent code completion (in-context method and variable suggestions) across all your files
and for built-in and third-party modules.
4.9.3.3. Search for symbols
You can search for symbols in the current file or workspace to navigate your code more quickly.
To search for a symbol in the current file, use Quick Open (Ctrl+P) then enter the '@'
command, then enter the name of the symbol you're looking for. A list of potential matches
will appear and be filtered as you type. Choose from the list of matches to navigate to its
location.
To search for a symbol in the current workspace, start by pressing Ctrl+T, then enter the
name of the symbol. A list of potential matches will appear as before. If you choose a match
that was found in a file that's not already open, the file will be opened before navigating to
the match's location. Alternatively, you can also use Quick Open (Ctrl+P) then enter the '#'
command to search the current workspace. Ctrl+T is just the shortcut for the '#' commands,
respectively, so everything works the same.

Pag. 86 R Manual – User Manual


4.9.3.4. Peek Definition
You can take a quick look at how a symbol was defined by using the Peek Definition feature.
This feature displays a few lines of code near the definition inside a peek window so you can
take a look without navigating away from your current location.
To peek at a symbol's definition, place your cursor on the symbol anywhere it's used in your
source code and then press Alt+F12. Alternatively, you can choose Peek Definition from the
context menu (right-click, then choose Peek Definition).
4.9.3.5. Go to Definition
You can also quickly navigate to where a symbol is defined by using the Go to Definition
feature.
To go to a symbol's definition, place your cursor on the symbol anywhere it is used in your
source code and then press F12. Alternatively, you can choose Go to Definition from the
context menu (right-click, then choose Go to Definition). When there's only one definition of
the symbol, you'll navigate directly to its location, otherwise the competing definitions are
displayed in a peek window as described in the previous section and you have to choose the
definition that you want to go to.
Other code editing features include:
 Code formatting
 Code snippets
 Code outline
 Code lens (references)
 Javadoc hovers
 Rename
 Highlights
4.9.4. Debugging
Debugger for Java is a lightweight Java Debugger based on Java Debug Server. It works
with Language Support for Java by Red Hat to allow users debugging Java code using
Visual Studio Code (VS Code).
The Java Debugger supports following features:
 Launch/Attach - You can either launch the Java project within VS Code or attach to any
running JVM process in debug mode, locally or remotely.
 Breakpoints - Conditional breakpoints by Hit Count and expression evaluation are supported
and can easily be set using the inline breakpoint settings window. This allows you to
conveniently add conditional breakpoints to your code, directly in the source viewer, without
requiring a modal window. Break on exceptions is also supported.
 Control flow – Including Pause, Continue F5, Step over F10, Step into F11, Step out
Shift+F11
 Data inspection - When you're stopped at a breakpoint, the debugger has access to the
variable names and values that are currently stored in memory. Inspect/Watch/Set Variables are
supported.
 Diagnostics - The CALL STACK panel shows the call stack of your program and allows you to
navigate through the call path of each captured allocation. Multi-threaded debugging is
supported by parallel stacks.
 Debug Console - The Debug Console lets you see information from both stdout and stderr.
 Hot Code Replacement - A very useful feature to facilitate experimental development and
iterative trial-and-error coding.

R Manual – User Manual Pag. 87


The debugger is able to detect your launch class in most cases, all you need to do is start
debugging by pressing F5. If you'd like to define the debugging configuration yourself, just
follow the steps below:
1. Switch to the Debug view (Ctrl+Shift+D).
2. Open launch.json to add a debug configuration for Java.
3. Fill in the mainClass for Launch setting or hostName and port for Attach.
4. Click Start button or press F5 to start debugging.

Pag. 88 R Manual – User Manual


For more debugging related information, please visit Java Debugging.
4.9.5. Testing
With the support from the Java Test Runner extension, you can easily run, debug and
manage your Java test cases.

Your test cases are identified automatically.

Currently the Test Runner supports JUnit4. We're working on JUnit5 and TestNG and will be
supporting them soon.

R Manual – User Manual Pag. 89


4.9.5. Spring Boot and Tomcat
To further improve your Java productivity in VS Code, there are extensions for most popular
frameworks and tools such as Spring Boot and Tomcat created by the community.
The Tomcat extension includes an explorer to easily navigate and manage your Tomcat
servers. You can create, start, debug, stop and rename your Tomcat server all with the
extension.

See Java Tutorial with VS Code to learn more about Tomcat and basic Java support with VS
Code.
Spring Boot support is provided by an extension from Pivotal, who also provide extensions
for popular platforms such as Cloudfoundry, Concourse and BOSH. There's also a Spring
Initializr Java Support extension so you can create a Spring Boot app from scratch.
See Spring Boot with VS Code to learn more about Spring Boot support with VS Code.
4.9.6. Next Steps
Learn more about Java in VS Code
 Java Tutorial with VS Code
 Spring Boot with VS Code
 Java Debugging and Testing
Read on to find out about:
 Basic Editing - Learn about the powerful VS Code editor.
 Code Navigation - Move quickly through your source code.
 Tasks - use tasks to build your project and more
 Debugging - find out how to use the debugger with your project

Pag. 90 R Manual – User Manual


PHP programming in VS Code
Visual Studio Code is a great editor for PHP development. You get features like syntax highlighting
and bracket matching, IntelliSense (code completion), and snippets out of the box and you can
add more functionality through community created VS Code extensions.

PHP extensions
There are many PHP language extensions available on the VS Code Marketplace and more are
being created. You can search for PHP extensions from within VS Code in the Extensions view
(Ctrl+Shift+X) then filter the extensions drop down list by typing php.

PHP IntelliSense
2931.2K
felixfbecker
Advanced Autocompletion and Refactoring support f...

Code Runner
2895.6K
formulahendry
Run C, C++, Java, JS, PHP, Python, Perl, Ruby, Go...

R Manual – User Manual Pag. 91


PHP Debug
1351.5K
felixfbecker
Debug support for PHP with XDebug

HTML CSS Support


1213.5K
ecmel
CSS support for HTML documents

Tip: The extensions shown above are dynamically queried. Click on an extension tile above to read
the description and reviews to decide which extension is best for you. See more in
the Marketplace.

Tip: The following setting allows to disable the built-in PHP completions in favor of proposals
created by installed PHP extensions.

 php.suggest.basic: Configures if the built-in PHP language suggestions are enabled.


Enabled by default.

Snippets
Visual Studio Code includes a set of common snippets for PHP. To access these, hit Ctrl+Space to
get a context specific list.

Pag. 92 R Manual – User Manual


Linting
VS Code uses the official PHP linter (php -l) for PHP language diagnostics. This allows VS Code to
stay current with PHP linter improvements.
Tip: Using XAMPP? Install the full version of PHP in order to obtain the development libraries.

There are three settings to control the PHP linter:

 php.validate.enable: controls whether to enable PHP linting at all. Enabled by default.


 php.validate.executablePath: points to the PHP executable on disk. Set this if the PHP
executable is not on the system path.
 php.validate.run: controls whether the validation is triggered on save (value: "onSave")
or on type (value: "onType"). Default is on save.

To set the PHP executable path, open your User or Workspace Settings and add
the php.validate.executablePath:

Windows

R Manual – User Manual Pag. 93


{
"php.validate.executablePath": "c:/php/php.exe"
}

Linux and macOS


{
"php.validate.executablePath": "/usr/bin/php"
}

Debugging
PHP debugging with XDebug is supported through a PHP Debug extension. Follow the extension's
instructions for configuring XDebug to work with VS Code.

Next Steps
Read on to find out about:

 Extension Marketplace - Browse the extensions others have shared


 Debugging - Learn more about VS Code debugging

Python in Visual Studio Code


Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun,
and productive. The extension works with different Python interpreters as well as Anaconda. It
leverages all of VS Code's power to provide auto complete and IntelliSense, linting, debugging,
and unit testing, along with the ability to easily switch between Python environments, including
virtual and conda environments.

Install Python and the Python extension


The tutorial guides you through installing Python and using the extension.

Autocomplete and IntelliSense


The Python extension supports code completion and Intellisense. Intellisense is a general term for
a number of features, including intelligent code completion (in-context method and variable
suggestions) across all your files and for built-in and third-party modules.
IntelliSense quickly shows methods, class members, and documentation as you type, and you can
trigger completions at any time with Ctrl+Space.

Pag. 94 R Manual – User Manual


Linting
Linting analyzes your Python code for potential errors, making it easy to navigate to and correct
different problems.
The Python extension can apply a number of different linters including Pylint, Pep8, Flake8, mypy,
pydocstule, prospector, and pylama. See Linting.

Debugging
No more print statement debugging! Set breakpoints, inspect data, and use the debug console
as you run your program step by step. Debug a number of different type of Python applications,
including multi-threaded, web, and remote applications.
For Python-specific details, including setting up your launch.json configuration, see Debugging.
General VS Code debugging information is found in the debugging document.

Snippets
Snippets take productivity to the next level. You can configure your own snippets and use snippets
provided by an extension. Snippets appear in the same way as code completion Ctrl+Space.

Environments
The Python extension automatically detects Python interpreters that are installed in standard
locations. It also detects conda environments as well as virtual environments in the workspace
folder. See Configuring Python environments.
The current environment is shown on the left side of the Visual Studio Code status bar:

This environment is used for IntelliSense, auto-completions, linting, formatting, and any other
language-related feature other than debugging. It is also activated when you use run Python in a
terminal.
To change the current interpreter, which includes switching to conda or virtual environments, click
the interpreter on the status bar or use the Python: Select Interpreter command.

R Manual – User Manual Pag. 95


VS Code then prompts you with a list of detected environments as well as any you've added
manually to your user settings (see Configuring Python environments).

Run Python in the Terminal


The Python extension provides shortcuts to quickly run Python code in the current interpreter:

 From the editor: right-click anywhere in the editor and select Run Python File in Terminal.
If invoked on a selection, only that selection is run.
 From Explorer: right-click a Python file and select Run Python File in Terminal.

You can also use the Python: Create Terminal command to create a terminal with the current
environment activated.

Unit testing
The Python extension supports unit testing with the unittest, pytest, and nose test frameworks.
To run unit tests, you enable one of the frameworks in settings. Each framework also has specific
settings, such as arguments that identify paths and patterns for test discovery.
Once discovered, VS Code provides a variety of commands (on the status bar, the command
palette, and elsewhere) to run and debug tests, including ability to run individual test files and
individual methods.

Configuration
The Python extension provides a wide variety of settings for its various features. These are
described on their relevant topics, such as Editing code, Linting, Debugging, and Unit Testing. The
complete list is found in the Settings reference.

Other popular Python extensions


Additional Python language support can be added to to VS Code by installing other popular
Python extensions. For Jupyter support, we recommend the "Jupyter" extension from Don
Jayamanne.

1. Open the Extensions view (Ctrl+Shift+X).


2. Filter the extension list by typing 'python'.

Pag. 96 R Manual – User Manual


Python
8267.4K
ms-python
Linting, Debugging (multi-threaded, remote), Inte...

Code Runner
2895.6K
formulahendry
Run C, C++, Java, JS, PHP, Python, Perl, Ruby, Go...

R Manual – User Manual Pag. 97


MagicPython
682.9K
magicstack
Syntax highlighter for cutting edge Python.

Python for VSCode


494.5K
tht13
Python language extension for vscode

The extensions shown above are dynamically queried. Click on an extension tile above to read the
description and reviews to decide which extension is best for you. See more in the Marketplace.

Next steps
 Python tutorial - Walk through the core features of Python in VS Code.
 Editing Python - Learn about auto-completion, formatting, and refactoring for Python.
 Basic Editing - Learn about the powerful VS Code editor.
 Code Navigation - Move quickly through your source code.

Go programming in VS Code
Using the Go extension for Visual Studio Code, you get language features like IntelliSense, code
navigation, symbol search, bracket matching, snippets and many more that will help you
in Golangdevelopment.

Pag. 98 R Manual – User Manual


You can install the Go extension from the VS Code Marketplace.

IntelliSense
Auto completions
As you type in a Go file, you can see IntelliSense providing you with suggested completions. This
even works for members in current, imported, and not yet imported packages. Just type any
package name followed by ., and you will get suggestions for the corresponding package
members.
By setting go.autocompleteUnimportedPackages to true in your settings, you can also get
suggestion for packages that you could import. Select one of these suggestions and an import to
the selected package will be added to your file.
Tip: Use Ctrl+Space to trigger the suggestions manually.

Hover Information
Hovering on any variable, function, or struct will give you information on that item such as
documentation, signature, etc.

By default, the extension uses godef and godoc to get this information. You can choose to
use gogetdocinstead by changing the setting go.docsTool in your User or Workspace Settings.

Signature help
When you open the ( while calling a function, a pop-up provides signature help for the function.
As you keep typing the parameters, the hint (underline) moves to the next parameter.
R Manual – User Manual Pag. 99
Tip: Use Ctrl+Shift+Space to manually trigger the signature help when the cursor is inside
the ()in the function call.

The extension's signature help also uses godef and godoc. You can choose to
use gogetdoc instead by changing the setting go.docsTool in your User or Workspace Settings.

Code navigation
Code navigation features are available in the context menu in the editor.

 Go To Definition F12 - Go to the source code of the type definition.


 Peek Definition Alt+F12 - Bring up a Peek window with the type definition.
 Find All References Shift+F12 - Find all references for the type.

You can navigate via symbol search using the Go to Symbol commands from the Command
Palette(Ctrl+Shift+P).

 Go to Symbol in File - Ctrl+Shift+O


 Go to Symbol in Workspace - Ctrl+T

You can also navigate back and forth between a Go file and its test implementation using the Go:
Toggle Test File command.

Build, Lint and Vet


On save, the Go extension can run go build, go vet and your choice of linting tool
(golint or gometalinter) on the package of the current file. You can control these features via
the settings below:

 go.buildOnSave
 go.buildFlags
 go.vetOnSave
 go.vetFlags
 go.lintOnSave
 go.lintFlags
 go.lintTool
 go.testOnSave

Pag. 100 R Manual – User Manual


The errors and warnings from running any/all of the above will be shown red/green squiggly lines
in the editor. These also show up in the Problems panel (View > Problems).

Formatting
You can format your Go file using Shift+Alt+F or by running the Format Document command
from the Command Palette or the context menu in the editor.
By default, formatting is run when you save your Go file. You can disable this behavior by
setting go.formatOnSave to false.
You can choose among three formatting tools: gofmt, goreturns and goimports by changing the
setting go.formatTool.

Test
There are many test related commands that you can explore by typing "Go: test" in the Command
Palette.

The first three above can be used to generate test skeletons for the functions in the current
package, file or at cursor using gotests. The last few can be used to run tests in the current
package, file or at cursor using go test. There is also a command for getting test coverage.

Import packages
Run the command Go: Add Import to get a list of packages that can be imported to your Go file.
Choose one and it will get added in the import block of your Go file.

Rename Symbols
You can rename symbols using F2 or by running the Rename Symbol command in the context
menu in the editor.

R Manual – User Manual Pag. 101


Debugging
The Go extension lets you debug Go code as well. You will need to install the Delve debugger
manually as a prerequisite. Read Debugging Go code using VS Code for setup steps, information
on remote debugging and a troubleshooting guide.

Next Steps
This has been a brief overview showing the Go extension features within VS Code. For more
information, see the details provided in the Go extension README.
To stay up to date on the latest features/bug fixes for the Go extension, see the CHANGELOG.
If you have any issues or feature requests, feel free to log them in the Go extension repo.
If you'd like to learn more about VS Code, try these topics:

 Basic Editing - A quick introduction to the basics of the VS Code editor.


 Install an Extension - Learn about other extensions are available in the Marketplace.
 Code Navigation - Move quickly through your source code.

Working with Docker


Docker is a very popular container platform that lets you easily package, deploy, and consume
applications and services. Whether you are a seasoned Docker developer or just getting started,
Visual Studio Code makes it easy to author Dockerfile and docker-compose.yml files in your
workspace.

Install the Docker extension


Docker support for VS Code is provided by an extension. To install the Docker extension, open the
Extension Viewlet by pressing Ctrl+Shift+X and search for vscode-docker to filter the results.
Select the Docker Support extension.

While here, you can install many other extensions to make you more productive with VS Code.

Pag. 102 R Manual – User Manual


Docker
2711.0K
PeterJausovec
Adds syntax highlighting, commands, hover tips, a...

Better Comments
84.3K
aaron-bond
Improve your code commenting by annotating with a...

Docker Explorer
45.3K
formulahendry
Manage Docker Containers, Docker Images, Docker H...

R Manual – User Manual Pag. 103


Docker Linter
44.3K
henriiik
Lint perl, python and/or ruby in your docker cont...

Tip: The extensions are dynamically queried. Click on an extension tile to read the description and
reviews to decide which extension is best for you. See more in the Marketplace.

Dockerfiles
With Docker, you can build images by specifying the step by step commands needed to build the
image in a Dockerfile. A Dockerfile is just a text file that contains the build instructions.
VS Code understands the structure of Dockerfiles as well as the available set of instructions,
meaning we can give you a great experience when authoring these files in the tool.

1. Create a new file in your workspace named Dockerfile


2. Press Ctrl+Space to bring up a list of snippets corresponding to
valid Dockerfile commands

3. Press Tab to move between fields within the snippet. For example, with the COPY snippet
you can fill in the source and then press Tab to move to the dest field.

Pag. 104 R Manual – User Manual


In addition to snippets for authoring your Dockerfile, Visual Studio Code will provide you with a
description of any Docker command you hover over with the mouse. For example, when hovering
over WORKDIR you will see the following.

For more information on Dockerfiles, check out Dockerfile best practices on docker.com.

Docker Compose
Docker Compose lets you define and run multi-container applications with Docker. You define
what the shape of these containers look like with a file called docker-compose.yml.
Visual Studio Code's experience for authoring docker-compose.yml is also very rich, providing
IntelliSense for valid Docker compose directives and it will query Docker Hub for metadata on
public Docker images.

1. Create a new file in your workspace called docker-compose.yml


2. Define a new service called web:
3. On the second line, bring up IntelliSense by pressing Ctrl+Space to see a list of all valid
compose directives.

R Manual – User Manual Pag. 105


4. For the image directive, you can press Ctrl+Space again and VS Code will query the Docker
Hub index for public images.

VS Code will first show a list of popular images along with metadata such as the number of stars
and description. If you continue typing VS Code will query the Docker Hub index for matching
images, including searching public profiles. For example, searching for Microsoft will show you all
the public Microsoft images.

Docker commands

Pag. 106 R Manual – User Manual


Many of the most common Docker and docker-compose commands are built right into
the Command Palette (Ctrl+Shift+P).

Running commands on Linux


By default, Docker runs as the root user on Linux, requiring other users to access it with sudo. This
extension does not assume root access, so you will need to create a Unix group called "docker"
and add users to it. Instructions can be found here: Create a Docker group

Transact-SQL in VS Code
Turn Visual Studio Code into a powerful editor for Transact-SQL (T-SQL) development with
the mssqlextension available in the VS Code Marketplace. The mssql extension is optimized to
work with SQL Server running on-premises, in any cloud, Azure SQL Database, and Azure SQL Data
Warehouse.
Connect to SQL databases, type T-SQL code, execute T-SQL code, view results, and save results as
JSON or CSV files. While typing T-SQL code, you get rich T-SQL language features like T-SQL
IntelliSense (code completion), syntax highlighting, linting, code navigation and code snippets.
Download VS Code - If you haven't downloaded VS Code yet, quickly install for your platform
(Linux, Mac or Windows).
R Manual – User Manual Pag. 107
Install T-SQL support
Add T-SQL language support to VS Code by installing the mssql extension from the VS Code
marketplace as follows:

1. Open the Extensions view from VS Code Side Bar (Ctrl+Shift+X).


2. Type "mssql" in the search bar, click Install, and reload VS Code when prompted.

Connect and Execute T-SQL


Easily connect to SQL Server running on-premises, in any cloud, Azure SQL Database, and Azure
SQL Data Warehouse. Then, execute your T-SQL statements and batches to view results and
messages - all within VS Code. Your recent connections are saved across sessions so you can
quickly connect to your databases again.

Pag. 108 R Manual – User Manual


R Manual – User Manual Pag. 109
View and Save Results
View results and messages when you execute your T-SQL code. Save results as a JSON or CSV file
to use the data in your applications with just a few clicks.

Pag. 110 R Manual – User Manual


R Manual – User Manual Pag. 111
T-SQL IntelliSense
As you type T-SQL code in the editor, VS Code provides intelligent code completion for T-SQL
keywords, suggestions for schema object names (tables, columns, views), and parameter help for
functions and procedures when connected to a database.

Pag. 112 R Manual – User Manual


R Manual – User Manual Pag. 113
Linting
Linting is the analysis of your T-SQL code for potential syntax errors. Use Visual Studio Code to
quickly navigate to the errors and warnings in your T-SQL code as you type.

Peek Definition/Go to Definition


Use Peek Definition and Go to Definition to quickly browse the definition of schema objects in
your database such as tables, functions, and procedures while typing T-SQL code.

Pag. 114 R Manual – User Manual


R Manual – User Manual Pag. 115
Snippets
T-SQL snippets provide code templates for commonly used T-SQL statements. Type "sql" to get
the list of T-SQL snippets.

Pag. 116 R Manual – User Manual


Next Steps
R Manual – User Manual Pag. 117
 Download the free SQL Server 2016 Developer Edition.
 Install the mssql extension from the Visual Studio Code Marketplace.
 Build an app using SQL Server - Get started with SQL Server on macOS, Linux, and Windows
using your favorite programming language.
 Contribute to the mssql extension on GitHub. Submit a bug report or a feature suggestion
on our GitHub Issue Tracker.

Further Reading
 SQL Server documentation
 SQL Server on Linux documentation
 SQL Server Blog
 SQL Server Videos on Channel9

Working with C#
The C# support in VS Code is optimized for cross-platform .NET Core development (see working
with .NET Core and VS Code for another relevant article). Our focus with VS Code is to be a great
editor for cross-platform C# development.

VS Code supports debugging of C# applications running on either .NET Core or Mono.


For detailed instructions on:

 .NET Core debugging - see the Microsoft C# extension's GitHub page.


 Mono debugging - see the Mono Debug extension's README.

Note: VS Code has limited support for debugging applications running on the Desktop .NET
Framework.

Pag. 118 R Manual – User Manual


Due to this focus, many standard C# project types are not recognized by VS Code. An example of a
non-supported project type is an ASP.NET MVC Application (though ASP.NET Core is supported).
In these cases, if you want to have a lightweight tool to edit a file - VS Code has you covered. If
you want the best possible experience for those projects and development on Windows in general,
we recommend you use Visual Studio Community.

Installing C# support
C# language support is an optional install from the Marketplace. You can install it from within VS
Code by searching for 'C#' in the Extensions view (Ctrl+Shift+X) or if you already have a project
with C# files, VS Code will prompt you to install the extension as soon as you open a C# file.
Video Tutorial on Getting Started with C# in VS Code with .NET Core
In addition to the Microsoft C# extension, the community has produced other extensions.

C#
5353.1K
ms-vscode
C# for Visual Studio Code (powered by OmniSharp).

Code Runner
2895.6K
formulahendry
Run C, C++, Java, JS, PHP, Python, Perl, Ruby, Go...

C# FixFormat
265.3K
Leopotam
Fix format of usings / indents / braces / empty l...

R Manual – User Manual Pag. 119


C# Extensions
189.8K
jchannon
C# IDE Extensions for VSCode

Tip: The extensions shown above are dynamically queried. Click on an extension tile above to read
the description and reviews to decide which extension is best for you. See more in
the Marketplace.

Roslyn and OmniSharp


Visual Studio Code uses the power of Roslyn and OmniSharp to offer an enhanced C# experience.
We offer support for:

 .NET Core projects


 MSBuild projects
 C# scripts (CSX)

On startup the best matching projects are loaded automatically but you can also choose your
projects manually. The status bar will show what projects have been loaded and also allows you to
select a different set of projects. To do so, click on the status bar projects item and select Change
projects…. In the image below a single project has been picked up:

The available options include:

 Selecting a project.json file will open a .NET Core project and VS Code will load that
project plus the referenced projects.
 Selecting a *.sln file opens a MSBuild-project. It will load the
referenced *.csproj projects and sibling or descendant project.json files but no other
project files that are referenced from the solution file.
 Selecting a folder will make VS Code scan for *.sln, project.json and *.csx files (C#
scripts) and VS Code will attempt to load them all.

Once the project is loaded the enhanced experiences light up...

Editing Evolved

Pag. 120 R Manual – User Manual


There is a lot to discover with C# and the editor, such as format on type, IntelliSense, the rename-
refactoring, etc.

For a full description of our editing features, go to the Basic Editing and Code
Navigation documentation.
Here are a few highlights...

IntelliSense
IntelliSense just works hit Ctrl+Space at any time to get context specific suggestions.

Snippets for C#
We have several built-in snippets included in VS Code that will come up as you type or you can
press Ctrl+Space (Trigger Suggest) and we will give you a context specific list of suggestions.

Tip: You can add in your own User Defined Snippets for C#. Take a look at User Defined
Snippets to find out how.

R Manual – User Manual Pag. 121


Search for Symbols
There are also features outside the editor. One is the ability to search for symbols from wherever
you are. Hit Ctrl+T, start typing, and see a list of matching C# symbols. Select one and you’ll be
taken straight to its code location.

CodeLens
Another cool feature is the ability to see the number of references to a method directly above the
method. Click on the reference info to see the references in the Peek view. This reference
information updates as you type.
Note: Methods defined in object, such as equals and hashCode do not get reference
information due to performance reasons.

Tip: You can turn off references information displayed in CodeLens with
the editor.codeLenssetting.

Find References/Peek Definition


Pag. 122 R Manual – User Manual
You can click on the references of an object to find the locations of its use in place without losing
context. This same experience works in reverse where you can Peek the definition of an object and
see it inline without leaving your location.

Quick Fixes / Suggestions


There are some basic quick fixes supported in VS Code. You will see a lightbulb and clicking on it,
or pressing Ctrl+. provides you with a simple list of fixes/suggestions.

Next Steps
Read on to find out about:

 .NET Core Development - get up and running with cross-platform .NET


 Basic Editing - Learn about the powerful VS Code editor.
 Code Navigation - Move quickly through your source code.
 Tasks - use tasks to build your project and more
 Debugging - find out how to use the debugger with your project

Common Questions
Q: My Project won't load.

R Manual – User Manual Pag. 123


A: VS Code only supports a limited set of project types (primarily .NET Core). For full .NET project
support, we suggest you use Visual Studio Community.
Q: IntelliSense is not working.
A: This is typically as a result of the current project type not being supported. You can see an
indication in the OmniSharp flame in the bottom left hand side of the status bar.
Q: How do I build/run my project?
A: VS Code supports tasks for build and natively understand the output of MSBuild, CSC, XBuild.
Find out more in the Tasks documentation.

Pag. 124 R Manual – User Manual

You might also like