An analytical apparatus with a function of plugging a container with a cap, comprising: a container mounting table configured to hold the container in a container setting position while being plugged; an optical sensor having at least one light source and at least one light detector arranged as a pair between which the container setting position is arranged, wherein said container setting position is arranged so that: - a region where the cap and the container overlap each other is irradiated with light of the light source when the container is placed at the container setting position; and - light emitted from the light source and having passed the container reaches the light detector as transmitted light, both in a situation where the cap is mounted on the container and in a situation where the cap is pressed into the container to complete the plugging, wherein the optical transmittance of the cap is not more than the optical transmittance of the container, and wherein the apparatus is configured to detect: - whether or not the container has been set, - whether or not the cap exists on the container, and - whether or not the cap is pressed into the container to complete the plugging, in accordance with a quantity of transmitted light detected by the light detector, wherein said apparatus is configured to: - prevent said cap member from being transferred onto the container until it has been detected that the container has been set in the container setting position; and - prevent the container from being transferred until it has been detected that the cap is pressed into the container to complete the plugging. a container mounting table configured to hold the container in a container setting position while being plugged; an optical sensor having at least one light source and at least one light detector arranged as a pair between which the container setting position is arranged, wherein said container setting position is arranged so that: - a region where the cap and the container overlap each other is irradiated with light of the light source when the container is placed at the container setting position; and - light emitted from the light source and having passed the container reaches the light detector as transmitted light, - a region where the cap and the container overlap each other is irradiated with light of the light source when the container is placed at the container setting position; and - light emitted from the light source and having passed the container reaches the light detector as transmitted light, both in a situation where the cap is mounted on the container and in a situation where the cap is pressed into the container to complete the plugging, wherein the optical transmittance of the cap is not more than the optical transmittance of the container, and wherein the apparatus is configured to detect: - whether or not the container has been set, - whether or not the cap exists on the container, and - whether or not the cap is pressed into the container to complete the plugging, - whether or not the container has been set, - whether or not the cap exists on the container, and - whether or not the cap is pressed into the container to complete the plugging, in accordance with a quantity of transmitted light detected by the light detector, wherein said apparatus is configured to: - prevent said cap member from being transferred onto the container until it has been detected that the container has been set in the container setting position; and - prevent the container from being transferred until it has been detected that the cap is pressed into the container to complete the plugging. - prevent said cap member from being transferred onto the container until it has been detected that the container has been set in the container setting position; and - prevent the container from being transferred until it has been detected that the cap is pressed into the container to complete the plugging.